我正在使用 VB.net 中的 XMLDocument 类。
我想获取名称为“a:Product”的元素,但代码如下:
dim doc as new XMLDocument
dim pr as XMLElement = doc.CreateElement("a:product")
pr.InnerText = "123"
doc.AppendChild(pr)
返回 XML 中不带“a:”的元素:
<product>123</product>
我哪里错了?
我正在使用 VB.net 中的 XMLDocument 类。
我想获取名称为“a:Product”的元素,但代码如下:
dim doc as new XMLDocument
dim pr as XMLElement = doc.CreateElement("a:product")
pr.InnerText = "123"
doc.AppendChild(pr)
返回 XML 中不带“a:”的元素:
<product>123</product>
我哪里错了?
改用这个:
dim pr as XMLElement = doc.CreateElement("a:product", namespaceURI);
namespaceURI
别名“a”表示的命名空间在哪里。这通常类似于“ http://schema.example.com/blahblah ”。只需在您的 XML 文件中查找即可。