次の構造を持つ元の xml があります。
<Root xmlns="http://xyz.com/2006/root" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xyz.com/2006/root.xsd">
新しい xml を作成するには、次のコードを使用します。
XNamespace ns = "http://xyz.com/2006/root";
XNamespace xsiNs = "http://www.w3.org/2001/XMLSchema-instance";
XDocument doc = new XDocument(
new XDeclaration("1.0", "UTF-8", null),
new XElement(ns + "root",
new XAttribute(XNamespace.Xmlns + "xsi", xsiNs),
new XAttribute(xsiNs + "schemaLocation",
"http://xyz.com/2006/root.xsd"),
));
結果は次のとおりです。
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xyz.com/2006/root.xsd" xmlns="http://xyz.com/2006/root">
ご覧のとおり、オリジナルでは xmls が最初の属性、xmls:xsi が 2 番目の属性、xsi:schemalocation が最後の属性です。新しい xml では、順序が異なります。
注文が重要かどうか知りたいです。
ただし、xml の詳細については、属性を並べ替える方法があるかどうかを知りたいと思います。
ありがとう。