Andy

Andy

  • NA
  • 1
  • 0

XML namespaces and prefixes

Apr 11 2009 1:52 PM
Hi,

I am trying to create a XML document with specific prefixes, something like the following:
  1. <my:doc>
  2.   <book:item property:changed="12/3/2009">Title </book>
  3.   <author:item property:changed="12/3/2009">admin</author>
  4. </doc>
I am creating a node the following way:

                    XmlDocument xmlDom;
                    XmlElement xmlItem;
                    XmlText xmlText;

                    xmlItem = xmlDom.CreateElement("MyTag");
                    XmlAttribute attr = xmlDom.CreateAttribute("attribute");
                    attr.InnerText = "Text";
                    xmlItem.Attributes.Append(attr);

                    xmlText = xmlDom.CreateTextNode("some text");
                    xmlItem.AppendChild(xmlText);

And the result is something like:

<MyTag attribute="Text">some text</MyTag>

I tried to add these prefixes with the xmlDom.CreateAttribute("","",""); method, but this doesn't seem to work. I am also stuck at setting the prefix/namespace of the XML tag (e.g. prefix:MyTag).

Any help would be appreciated... thanks in advance.