ete*_*ner 26 xmlwriter namespaces
我试图使用XmlWriter写出以下元素
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
Run Code Online (Sandbox Code Playgroud)
我已经完成了第一个声明
writer.WriteStartElement("kml", "http://www.opengis.net/kml/2.2");
Run Code Online (Sandbox Code Playgroud)
如何将剩余的3个声明添加到同一个元素?
Rya*_*n B 42
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");
Run Code Online (Sandbox Code Playgroud)
来自https://msdn.microsoft.com/en-us/library/cfche0ka(v=vs.100).aspx.
Ryan B的答案是不完整的,因为 XML 命名空间仅作为属性写入但未在名称表中注册,因此LookupPrefix无法获取 XML 命名空间之一的前缀 fi http://www.w3.org/2005/Atom。它将返回null代替atom。
编写命名空间属性并获取命名空间注册使用
writer.WriteAttributeString("atom",
"http://www.w3.org/2000/xmlns/",
"http://www.w3.org/2005/Atom");
Run Code Online (Sandbox Code Playgroud)
名称空间的使用http://www.w3.org/2000/xmlns/也在名称表中注册前缀。