Additional xmlns in xml created from xmlserializer

I created a class from a schema using the xsd.exe tool

Now, when I serialize the class, I get extra xmlns=""on everything under the root.

<myroot xmlns="blabla">
    <tag1 xmlns="">
        <tag2>
            ...

The diagram looks like this:

<xsd:schema xmlns="blabla" targetNamespace="blabla" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="MyRoot">

         

I see nothing in the diagram indicating that the element tag1 and below should be in a different namespace than the root.

The serialization code is simple:

MyRoot doc = new MyRoot();
...
XmlSerializer xs = new XmlSerializer(typeof(MyRoot));
MemoryStream ms = new MemoryStream();
try {
    xs.Serialize(ms, doc);

The class created from xsd.exe contains only the namespace attribute in the root class.

+3
source share
1 answer

What he does here is overriding the namespace "blabla"from the parent with the specific namespace "".

, , , tag1 ( , ) myroot "blabla".

, , tag1 , "blabla".

, , , , , .

+1

Source: https://habr.com/ru/post/1774099/


All Articles