"在':'字符,十六进制值0x3A,不能包含在名称和QUOT; [英] "The ':' character, hexadecimal value 0x3A, cannot be included in a name"

查看:782
本文介绍了"在':'字符,十六进制值0x3A,不能包含在名称和QUOT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码,会读一些XML文件(S)。我尝试不同的方法来解决这个问题,但不能。此外,我想这样的代码:

 命名空间我=htt​​p://schemas.microsoft.com/office/infopath/ 2003 / myXSD / 2011-01-11T08:31:30; 
的XElement myEgitimBilgileri = XDocument.Load(@C:\25036077.xml)元素(我的:+Egitim_Bilgileri);



不过,所有的时间同样的错误。原来这里是:



 私人无效button2_Click(对象发件人,EventArgs五)
{
的XElement myEgitimBilgileri =
XDocument.Load(@C:\25036077.xml)元素(我:Egitim_Bilgileri)。

如果(myEgitimBilgileri!= NULL)
{
的foreach(在myEgitimBilgileri.Elements的XElement元素())
{
Console.WriteLine(名称:{0} \tValue:{1},element.Name,element.Value.Trim());
}
}

Console.Read();
}

下面是我的XML文件的路径:

 <我:Egitim_Bilgileri> 
<我:egitimler_sap>
<我:sap_eduname>< /我:sap_eduname>
<我:sap_edufaculty>< /我:sap_edufaculty>
<我:sap_eduprofession>< /我:sap_eduprofession>
<我:sap_diplomno>< /我:sap_diplomno>
<我:sap_edulevel>< /我:sap_edulevel>
<我:sap_edustartdate XSI:零=真正的>< /我:sap_edustartdate>
<我:sap_eduenddate XSI:零=真正的>< /我:sap_eduenddate>
< /我:egitimler_sap>
< /我:Egitim_Bilgileri>



这是我的命名空间中的XML


$ B $路径b

 的xmlns:我=htt​​p://schemas.microsoft.com/office/infopath/2003/myXSD/2011-01-11T08:31:30

的xmlns:我=htt​​p://schemas.microsoft.com/office/infopath/2003/myXSD/2008-01-23T00:43:17


解决方案

中的代码元素(我的:+Egitim_Bilgileri)相同元素(我:Egitim_Bilgileri)这是用来表示该元素的命名的我的:Egitim_Bilgileri的在默认名称空间的(有一个从字符串隐式转换要的XName



然而,无效的在元素名称(命名空间分离之外),因此将导致运行时异常。



相反,代码应为元素(我+Egitim_Bilgileri),其中我的是的的XNamespace 对象。该的XNamespace对象的 + 运营商,当给定一个字符串作为第二个操作数,在的的XName 对象=库/ system.xml.linq.xname.aspx http://msdn.microsoft.com/en-us/library/bb348975.aspx > 元素(的XName)



例如:

 的XNamespace我=htt​​p://schemas.microsoft.com/office/infopath/2003/myXSD/2011-01-11T08:31:30; 
的XDocument DOC = XDocument.Load(@C:\25036077.xml);
//可以省略以下变量/分配,
//这是显示的XNamespace的运算符+,它是如何造成的XName
的XName节点名称=我+Egitim_Bilgileri
的XElement myEgitimBilgileri = doc.Element(节点名称); )

$ B:

哀悼不必处理的InfoPath

快乐编码...和
$ b




我更喜欢在大多数情况下,使用XPath。除其他事项外,它允许轻松地选择嵌套的节点,避免了以检查空每个级别可与 node.Element(X).Element(Y)结构需要

 使用System.Xml.XPath; //为XPathSelectElement扩展方法
XmlNamespaceManager的NS =新的XmlNamespaceManager(新NameTable());
ns.AddNamespace(我的,http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-01-11T08:31:30)
//注意没有的XName对象。相反,XPath字符串被解析
//和命名空间分辨率通过XmlNamespaceManager的
的XElement myEgitimBilgileri = doc.XPathSelectElement发生(:myFields /我的:/我Egitim_Bilgileri,NS);


I have a code which will read some xml file(s). I tried different ways to solve this problem, but couldn't. Also I tried to code like this:

Namespace my = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-01-11T08:31:30";                
XElement myEgitimBilgileri = XDocument.Load(@"C:\25036077.xml").Element("my:"+ "Egitim_Bilgileri"); 

But all the time the same mistake. Here is the original:

private void button2_Click(object sender, EventArgs e)
{                               
    XElement myEgitimBilgileri =    
    XDocument.Load(@"C:\25036077.xml").Element("my:Egitim_Bilgileri");

    if (myEgitimBilgileri != null)
    {
        foreach (XElement element in myEgitimBilgileri.Elements())
        {
            Console.WriteLine("Name: {0}\tValue: {1}", element.Name, element.Value.Trim());
        }
    }

    Console.Read();
}

Here is a path of my xml file:

<my:Egitim_Bilgileri>
        <my:egitimler_sap>
            <my:sap_eduname></my:sap_eduname>
            <my:sap_edufaculty></my:sap_edufaculty>
            <my:sap_eduprofession></my:sap_eduprofession>
            <my:sap_diplomno></my:sap_diplomno>
            <my:sap_edulevel></my:sap_edulevel>
            <my:sap_edustartdate xsi:nil="true"></my:sap_edustartdate>
            <my:sap_eduenddate xsi:nil="true"></my:sap_eduenddate>
        </my:egitimler_sap>
    </my:Egitim_Bilgileri>

and this is the path of my namespace in XML

xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-01-11T08:31:30"

xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-01-23T00:43:17"

解决方案

The code Element("my:" + "Egitim_Bilgileri") is the same as Element("my:Egitim_Bilgileri") which is taken to mean the element named "my:Egitim_Bilgileri" in the default namespace (there is an implicit conversion from string to XName).

However, : is invalid in an element name (outside of the namespace separation) and thus will result in a run-time exception.

Instead, the code should be Element(my + "Egitim_Bilgileri") where my is an XNamespace object. The XNamespace object's + operator, when given a string as the second operand, results in an XName object that can then be used with the Element(XName) method.

For instance:

XNamespace my = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-01-11T08:31:30";
XDocument doc = XDocument.Load(@"C:\25036077.xml");
// The following variable/assignment can be omitted,
// it is to show the + operator of XNamespace and how it results in XName
XName nodeName = my + "Egitim_Bilgileri";
XElement myEgitimBilgileri = doc.Element(nodeName);

Happy coding... and condolences for having to deal with InfoPath :)


I prefer to use XPath in most cases. Among other things it allows easily selecting nested nodes and avoids having to "check for null" each level as may be required with node.Element(x).Element(y) constructs.

using System.Xml.XPath; // for XPathSelectElement extension method
XmlNamespaceManager ns = new XmlNamespaceManager(new NameTable());
ns.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-01-11T08:31:30")
// Note that there is no XName object. Instead the XPath string is parsed
// and namespace resolution happens via the XmlNamespaceManager
XElement myEgitimBilgileri = doc.XPathSelectElement("/my:myFields/my:Egitim_Bilgileri", ns);

这篇关于&QUOT;在':'字符,十六进制值0x3A,不能包含在名称和QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆