Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerate XML from multiple classes
    primarykey
    data
    text
    <p>I'm trying to generate an XML document using a class generated by the xsd.exe tool.</p> <p>The desired structure is like this:</p> <pre><code> &lt;sh:StandardBusinessDocument xmlns:eanucc="urn:ean.ucc:2" xmlns:order="urn:ean.ucc:order:2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader ../Schemas/sbdh/StandardBusinessDocumentHeader.xsd urn:ean.ucc:2 ../Schemas/OrderProxy.xsd" xmlns:sh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"&gt; &lt;sh:StandardBusinessDocumentHeader&gt; &lt;sh:HeaderVersion&gt;2.2&lt;/sh:HeaderVersion&gt; &lt;/sh:StandardBusinessDocumentHeader&gt; &lt;eanucc:message&gt; &lt;entityIdentification&gt; &lt;uniqueCreatorIdentification&gt;2222&lt;/uniqueCreatorIdentification&gt; &lt;/entityIdentification&gt; &lt;/eanucc:message&gt; &lt;/sh:StandardBusinessDocument&gt; </code></pre> <p>But I have only been able to achieve this:</p> <pre><code>&lt;sh:StandardBusinessDocument xmlns:eanucc="urn:ean.ucc:2" xmlns:order="urn:ean.ucc:order:2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader ../Schemas/sbdh/StandardBusinessDocumentHeader.xsd urn:ean.ucc:2 ../Schemas/OrderProxy.xsd" xmlns:sh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"&gt; &lt;sh:StandardBusinessDocumentHeader&gt; &lt;sh:HeaderVersion&gt;2.2&lt;/sh:HeaderVersion&gt; &lt;/sh:StandardBusinessDocumentHeader&gt; &lt;sh:message&gt; &lt;entityIdentification&gt; &lt;uniqueCreatorIdentification&gt;2222&lt;/uniqueCreatorIdentification&gt; &lt;/entityIdentification&gt; &lt;/sh:message&gt; &lt;/sh:StandardBusinessDocument&gt; </code></pre> <p>How can I create the differing node prefixes for the children of the root node? In my generated class I have added the namespaces using the XmlTypeAttribute and XmlRootAttribute but these are ignored for the second child attribute. My classes have the attributes as below:</p> <pre><code>[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader")] [System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader", IsNullable = true)] public class StandardBusinessDocument { private StandardBusinessDocumentStandardBusinessDocumentHeader standardBusinessDocumentHeaderField; private StandardBusinessDocumentMessage messageField; } [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader")] [System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader", IsNullable = false)] public class StandardBusinessDocumentStandardBusinessDocumentHeader : StandardBusinessDocument { } [System.Xml.Serialization.XmlTypeAttribute(Namespace = "urn:ean.ucc:2")] [System.Xml.Serialization.XmlRootAttribute(Namespace = "urn:ean.ucc:2", IsNullable = true)] public class StandardBusinessDocumentMessage { } </code></pre> <p>Any ideas why the decoration on the second child (StandardBusinessDocumentMessage) is ignored?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload