XAttribute Generating strange namespaces
Posted
by Adam Driscoll
on Stack Overflow
See other posts from Stack Overflow
or by Adam Driscoll
Published on 2010-04-16T18:39:03Z
Indexed on
2010/04/16
18:43 UTC
Read the original article
Hit count: 279
I'm constructing an XElement with a couple attributes that have different namespaces. The code looks like this:
var element = new XElement("SynchronousCommand",
new XAttribute("{wcm}action", "add"),
new XAttribute("{ns}id", Guid.NewGuid()),
new XElement...
);
The XML that is generated looks like this:
<unattend xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:schemas-microsoft-com:unattend">
<SynchronousCommand d5p1:action="add" d5p2:id="c0f5fc6d-d407-4d3d-8a05-d84236cca2fb" xmlns:d5p2="ns" xmlns:d5p1="wcm">
...
</SynchronousCommand>
</unattend>
I'm just wondering if the auto-generated d5p2 is valid and why it is doing this. According to the XML standards here it seems like it would be valid. But why is it not:
<unattend xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:schemas-microsoft-com:unattend">
<SynchronousCommand wcm:action="add" ns:id="c0f5fc6d-d407-4d3d-8a05-d84236cca2fb" >
To generate the XML I'm doing this:
public class unattend
{
public List<XElement> Any {get;}
}
var unattend = new unattend();
unattend.Add(element);
serializer.Serialize(xmlWriter, unattend);
© Stack Overflow or respective owner