Dan B
Dan B

Reputation: 357

How do I rename xmlns="" with WriteStartElement?

I'm attempting to make an XML that's going to be parsed by an XNA content reader. I'm using XMLWriter, and the format is supposed to be:

<XNAContent>
     <Assest Type="namespace">
          <Element>"Value"</Element>
     </Asset>
<XNAContent>

But when I use WriteStartElement to declare a namespace, I get:

 <XNAContent>
     <Assest xmlns="namespace">
          <Element>"Value"</Element>
     </Asset>
<XNAContent>

It's important that I have Asset Type= instead of Asset xmlns= because of what the pipeline expects, but I can't find an overload that let's me rename that default tag.

Is there a way for XMLWriter to let me put my own tag there as described? Thanks, all.

Upvotes: 1

Views: 1266

Answers (1)

ColinE
ColinE

Reputation: 70170

You are confusing XML attributes with namespaces, xmlns is a 'special' attribute that defines the namespace for an XML element and its children. Whereas your Type is simple an attribute. To write an attribute value use the WriteAttributeString method.

For example:

 writer.WriteStartElement("Asset");

 writer.WriteAttributeString("Type", "namespace");

 writer.WriteEndElement();

will result in

<Asset Type="namespace">
</Asset>

Upvotes: 3

Related Questions