问题
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