Problems with creating nodes with XmlWriter -- "mis" as prefix

64 views Asked by At

My first attempt to generate this type of file, not very familiar, please help me. I want to achieve the following effect

 <ExtendedData xmlns:mis="www.dji.com">
   <mis:actions param="240" label="zoom" >CameraZoom</mis:actions>
</ExtendedData>

my code is

 writer.WriteStartElement("mis", "ExtendedData", "www.dji.com");
 writer.WriteStartElement("mis", "actions", "www.dji.com");
                writer.WriteAttributeString("param", "240");
                writer.WriteAttributeString("label", "zoom");
                writer.WriteString("CameraZoom");
                writer.WriteEndElement();

It works like this:

 <mis:ExtendedData xmlns:mis="www.dji.com">
   <mis:actions param="240" label="zoom" >CameraZoom</mis:actions>
</mis:ExtendedData>

What do I need to do to remove the "mis:" prefix from " <mis:ExtendedData xmlns:mis="www.dji.com">"

1

There are 1 answers

3
Michael Kay On BEST ANSWER

The Microsoft documentation (I assume this is the .NET XmlWriter?) gives the example

// Write an element (this one is the root).
writer.WriteStartElement("book");

// Write the namespace declaration.
writer.WriteAttributeString("xmlns", "bk", null, "urn:samples");

for writing a no-namespace element with a namespace declaration that's not actually used in the element name.