Adding XML elements in the right order

别说谁变了你拦得住时间么 提交于 2019-12-24 01:49:43

问题


I want to add elements to the XDocument object and the order of the elements for that XML I want to build is defined in a XSD e.g.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Address">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Recipient"/>
        <xs:element name="City"/>
     </xs:sequence>
      </xs:complexType>
  </xs:element>
  </xs:schema>

Now I want to add the following two XElements

XDocument doc = new XDocument(new XElement("Address"));
doc.Root.Add(new XElement("City"));
doc.Root.Add(new XElement("Recipient"));

Can does XDocument automatically bring the elements into the right order by reference to the xsd? So if I write the XDocument to string the element Recipient should written first and then the element City.

来源:https://stackoverflow.com/questions/35330636/adding-xml-elements-in-the-right-order

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!