我有一个如下所示的 XML 文档:
<?xml version="1.0" encoding="utf-8"?>
<entry xml:base="https://sps.utility.abc123.com/sites/xyz/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:etag=""5"">
<id>Web/Lists(guid'c920cb93-a31a-49a0-a4d6-ac1cb8fb0658')/Items(2)</id>
<category term="SP.Data.REST_x0020_Test_x0020_ListListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" href="Web/Lists(guid'c920cb93-a31a-49a0-a4d6-ac1cb8fb0658')/Items(2)" />
<title />
<updated>2017-09-20T16:01:19Z</updated>
<author>
<name />
</author>
<content type="application/xml">
<m:properties>
<d:Title>item 2 has a new value.</d:Title>
</m:properties>
</content>
</entry>
我想在<d:Title>
节点上获取值,在这种情况下是item 2 has a new value.
当我使用以下内容时:
Private Function getFieldValueFromXml(xml As Variant, fieldName As String)
Dim node As IXMLDOMNode
Dim namespaceAndName As String
Dim domDoc as MSXML2.DomDocument60
namespaceAndName = "d:" & fieldName
Set domDoc = New DOMDocument60
Set node = domDoc.SelectSingleNode(namespaceAndName)
getFieldValueFromXML = node.Text
End Function
该SelectSingleNode()
调用引发此错误:
Reference to undeclared namespace prefix: 'd'.
如果我尝试首先设置节点,也会发生这种情况m
,如下所示:
Set node = domDoc.SelectSingleNode("m:properties")
我怎样才能得到<d:Title>
这里的内部文本?