VB.NET XML属性未正确显示

时间:2016-08-08 10:04:30

标签: xml vb.net attributes

我必须得到这个输出:

<Ricette xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Xml.xsd">

但我得到了这个:

<Ricette xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" noNamespaceSchemaLocation="Xml.xsd">

xsi:noNamespaceSchemaLocation 无法正确显示

这是我的一段代码:

Dim xmlnsXsiAttribute As XmlAttribute = myXmlDocument.CreateAttribute("xmlns:xsi")
xmlnsXsiAttribute.Value = "http://www.w3.org/2001/XMLSchema-instance"
Dim xsiAttribute As XmlAttribute = myXmlDocument.CreateAttribute("xsi:noNamespaceSchemaLocation")
xsiAttribute.Value = "Xml.xsd"
node.Attributes.Append(xmlnsXsiAttribute)
node.Attributes.Append(xsiAttribute)

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您可以使用String userId=preferences.getString("userId", null); String pwd=preferences.getString("pwd", null); 方法将命名空间属性添加到元素:

XmlElement.SetAttribute()

来自MSDN

....
node.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
node.SetAttribute("noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance", "Xml.xsd")
     

使用指定的本地名称和名称空间URI设置属性的值。