-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Serialized xml is missing some namespaces #303
Comments
Can you post a link to the schema here? |
While creating this minimal sample I think I found the real cause. First here is the sample as simple as it can get: A valid instance from my expectations should look like this: <ns0:SampleRoot xmlns:ns0="SampleNamespace">
<Direct>
<Direct1>Direct1_0</Direct1>
</Direct>
<ns0:ViaRef> <!-- <<<<<<<<<<<<<<<<<<<<<<<<<<< look here -->
<ViaRef1>ViaRef1_0</ViaRef1>
</ns0:ViaRef>
</ns0:SampleRoot> The given sample generates this: <?xml version="1.0"?>
<SampleRoot xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="SampleNamespace">
<Direct xmlns="">
<Direct1>direct1</Direct1>
</Direct>
<ViaRef xmlns=""> <!-- <<<<<<<<<<<<<<<<<<<<<<<<<<< look here -->
<ViaRef1>viaref1</ViaRef1>
</ViaRef>
</SampleRoot> Notice ViaRef beeing in the wrong namespace! For easy reference, the schema (also in the sample zip) is: <?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="SampleNamespace"
xmlns:b="http://schemas.microsoft.com/BizTalk/2003"
targetNamespace="SampleNamespace" version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="SampleRoot">
<xs:complexType>
<xs:sequence>
<xs:element name="Direct">
<xs:complexType>
<xs:sequence>
<xs:element name="Direct1" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element ref="ViaRef" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ViaRef">
<xs:complexType>
<xs:sequence>
<xs:element name="ViaRef1" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema> ...so I compared the generated classes from XmlSchemaClassGenerator against one from xsd.exe and I noticed, the major difference is in the attributes of the Property ViaRef! xsd.exe is not generating If I comment that line and run the test again, all the expectations are met! See comment here:
[System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "2.0.634.0")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute("SampleRoot", Namespace="SampleNamespace", AnonymousType=true)]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute("SampleRoot", Namespace="SampleNamespace")]
public partial class SampleRoot
{
[System.ComponentModel.DataAnnotations.RequiredAttribute()]
[System.Xml.Serialization.XmlElementAttribute("Direct", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public SampleRootDirect Direct { get; set; }
[System.ComponentModel.DataAnnotations.RequiredAttribute()]
//[System.Xml.Serialization.XmlElementAttribute("ViaRef", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public ViaRef ViaRef { get; set; }
} could it be that "easy" to not generate the XmlElementAttribute if the Element is referenced via |
Fixed via #304 |
I noticed I am getting wrong namespaces from the xmlserializer result. I have:
and as far as I can tell, the generated classes and attributes have all the correct namespaces in their attributes, but if I serialize an instance, i get:
But the UCI element is not in the empty namespace, so this is wrong!
the generated code for the relevant section:

I noticed, if I change the marked location to qualified, the deserialized document gets the correct namespaces written.
I am not sure how to proceed here. Did I do something wrong or is this a bug in the xml serialzer?
Help?!
The text was updated successfully, but these errors were encountered: