Adding multiple namespace declarations in XmlWriter

后端 未结 3 729
感动是毒
感动是毒 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.

提交回复
热议问题