[英]How do you grab an attribute of child node in XML
I'm looking for a method to grab the an attribute of a child node from the parent node.我正在寻找一种从父节点获取子节点属性的方法。 So far I have:
到目前为止,我有:
For each dataNodedsd in xmlDocBindings.SelectNodes("//dataobject")
nodesDsdID = dataNodedsd.getAttribute("objectid")
set parentNode = dataNodedsd.parentNode
if d.Exists(nodesDsdID) Then
d.item(nodesDsdID) = parentNode.getAttribute("ID")
paramstr = parentnode.selectsinglenode("property[@name='pointrefparamname']").text
msgbox paramStr
d2key = parentNode.getAttribute("ID")
'add ids to dict2
d2.add d2key, ""
End If
I am currently looking to pull paramstr from the parent node.我目前正在寻找从父节点拉 paramstr。 My current attempt was using the code provided
我目前的尝试是使用提供的代码
paramstr = parentnode.selectsinglenode("property[@name='pointrefparamname']").text
However I am failing to properly pull the string from the node.但是我无法从节点正确拉出字符串。
This is a sample of XML that I am attempting to pull from the node:这是我试图从节点中提取的 XML 示例:
<dataobject format="propertybag" type="HMIPage.Generic" id="3">
<property name="AddressFlags">1</property>
<property name="AddressType">0</property>
<property name="CalloutElement"/>
<property name="ObjectType">0</property>
<property name="ParameterFormat">0</property>
<property name="PointRefFlags">0</property>
<property name="PointRefParamName">PIDA.MODEFL.CAS</property>
<property name="PointRefParamOffset">0</property>
<property name="PointRefPointName">00FC1627</property>
<property name="PresentationType">0</property>
<property name="SecurityLevel">0</property>
<property name="UpdatePeriod">0</property>
<property name="version">1.3</property>
</dataobject>
I am simply trying to pull from我只是想从
<property name="PointRefParamName">PIDA.MODEFL.CAS</property>
and get the result并得到结果
PIDA.MODEFL.CAS
as a string.作为字符串。 So far everything I have looked up either hasn't been working(either to my incompetence/misunderstanding or lack of viable methodology. If anyone could clear this up it would be greatly appreciated. Once again I am simply attempting to grab an attribute from a child node within a parent node.
到目前为止,我查找的所有内容都没有奏效(由于我的无能/误解或缺乏可行的方法。如果有人能解决这个问题,我将不胜感激。再一次,我只是试图从父节点内的子节点。
This works for me in VBA这在 VBA 中对我有用
Sub getValXml()
Dim myDocument As DOMDocument30
Dim parNodes As IXMLDOMNodeList
Dim parNode As IXMLDOMNode
Dim myNode As IXMLDOMNode
Set myDocument = New DOMDocument30
myDocument.Load ("C:\temp\text.xml")
Set parNodes = myDocument.SelectNodes("//dataobject")
For Each parNode In parNodes
Set myNode = parNode.SelectSingleNode("property[@name='PointRefParamName']")
MsgBox myNode.Text
Next
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.