Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C中Xml文件的xmlns问题#_C#_Xml_Xml Namespaces - Fatal编程技术网

C# C中Xml文件的xmlns问题#

C# C中Xml文件的xmlns问题#,c#,xml,xml-namespaces,C#,Xml,Xml Namespaces,因为我不理解xmlns、xmlns:xsd和xmlns:xsi的关键字,所以我发布了这个问题 我找到了XpathNavigatorMoveToChile方法的一个示例,并附上了xml文件示例 XmlDocument document = new XmlDocument(); document.Load("contosoBooks.xml"); XPathNavigator navigator = document.CreateNavigator(); navigator.MoveToChild

因为我不理解
xmlns
xmlns:xsd
xmlns:xsi
的关键字,所以我发布了这个问题

我找到了XpathNavigator
MoveToChile
方法的一个示例,并附上了xml文件示例

XmlDocument document = new XmlDocument();
document.Load("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

navigator.MoveToChild("bookstore", "http://www.contoso.com/books");
MSDN中的示例Xml文件

<?xml version="1.0" encoding="utf-8" ?>
<bookstore xmlns="http://www.contoso.com/books">
    <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
        <title>The Autobiography of Benjamin Franklin</title>
        <author>
感谢您的回复。

请查看此

基本上,您可以为XML名称空间定义一个前缀,以使其更易于使用:

<Equipment 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <License licenseId="" licensePath=""/>
   <xsd:element ..... xsi:nil="true" />

属于默认命名空间的元素可能是您最需要的元素,因此您可以定义一个不带前缀的XML命名空间-默认命名空间:

<Equipment 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns="http://www.yourcompany.com/your/default/namespace" >
   <License licenseId="" licensePath=""/>
   <xsd:element ..... xsi:nil="true" />

现在,XML中没有特定前缀的所有元素(这里是
标记)都是默认XML命名空间的一部分。

请查看此项

基本上,您可以为XML名称空间定义一个前缀,以使其更易于使用:

<Equipment 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <License licenseId="" licensePath=""/>
   <xsd:element ..... xsi:nil="true" />

属于默认命名空间的元素可能是您最需要的元素,因此您可以定义一个不带前缀的XML命名空间-默认命名空间:

<Equipment 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns="http://www.yourcompany.com/your/default/namespace" >
   <License licenseId="" licensePath=""/>
   <xsd:element ..... xsi:nil="true" />

现在,XML中没有特定前缀的所有元素(这里是
标记)都是默认XML命名空间的一部分