Adding multiple namespace declarations in XmlWriter

后端 未结 3 710
感动是毒
感动是毒 2020-12-14 15:57

I am trying to write out the following element using XmlWriter



        
相关标签:
3条回答
  • 2020-12-14 16:36

    The answer of Ryan B is incomplete as the XML namespace is only written as attribute but not registered in the name table, so LookupPrefix will fail getting prefix of one of the XML namespaces, f.i. http://www.w3.org/2005/Atom. It will return null instead atom.

    To write a namespace attribute and get namespace registered use

    writer.WriteAttributeString("atom",
                                "http://www.w3.org/2000/xmlns/",
                                "http://www.w3.org/2005/Atom");
    

    Use of namespace http://www.w3.org/2000/xmlns/registers also the prefix in name table.

    0 讨论(0)
  • 2020-12-14 16:51
    writer.WriteAttributeString("xmlns","gx", null, "http://www.google.com/kml/ext/2.2");
    writer.WriteAttributeString("xmlns","kml", null, "http://www.opengis.net/kml/2.2");
    writer.WriteAttributeString("xmlns","atom", null, "http://www.w3.org/2005/Atom");
    

    Got that from https://msdn.microsoft.com/en-us/library/cfche0ka(v=vs.100).aspx.

    0 讨论(0)
  • 2020-12-14 16:55

    The namespaces are simply attributes. Use the standards means of writing attributes for the element.

    0 讨论(0)
提交回复
热议问题