0
필터링 된 하위 노드 값 Location = 'Local'
을 기반으로 속성 값 Name
을 가져 오려고합니다. 소스 XML은 다음과 같습니다자식 노드 값이 매개 변수와 일치하는 경우 XML 노드에서 속성 값 가져 오기
<?xml version="1.0"?>
<Root>
<User Name="user1">
<Element CreationDate="2014-11-16 18:05:44" ID="0a962d93-64e8-4caa-8a4d-e6e9b7df5af4" Name="ClienName1">
<AdditionalInfo>
<Client />
<Number />
<MasterMachine>LocalMachine1</MasterMachine>
<Location>Local</Location>
<Owner>Owner1</Owner>
</AdditionalInfo>
</Element>
<Element CreationDate="2014-11-21 16:08:53" ID="65ddadf1-f7e4-467c-aedf-3d6ba5c35d1d" Name="ClienName2">
<AdditionalInfo>
<Client />
<Number />
<MasterMachine>LocalMachine1</MasterMachine>
<Location>Local</Location>
<Owner>Owner1</Owner>
</AdditionalInfo>
</Element>
<Element CreationDate="2014-11-24 10:00:13" ID="469479c7-a249-4bf4-a486-fc09b13ba145" Name="ClienName3">
<AdditionalInfo>
<Client />
<Number />
<MasterMachine>ServerMachine1</MasterMachine>
<Location>Server</Location>
<Owner>Owner2</Owner>
</AdditionalInfo>
</Element>
</User>
</Root>
내가 지금까지 가지고하는 것은 :
Set objXML = CreateObject("MSXML2.DOMDocument")
objXML.setProperty "SelectionLanguage", "XPath"
objXML.Load XML
Set objElementNode = objXML.selectNodes("//Root/User/Element/@Name")
Set objLocationNode = objXML.selectNodes("//Root/User/Element/@Name/AdditionalInfo [Location='Local']/Location")
For Each elementName In objElementNode
For Each location In objLocationNode
strMessage = elementName.text &" "& location.text &vbCr
Next
Next
MsgBox strMessage
은 분명히 내가이 영역에서 단서가 없다. 이것은 지금까지 노드를 탐색하는 방법을 이해하지 못했지만 온라인에서 본 스 니펫을 기반으로합니다. AdditionalInfo 로컬 값을 가진 아이의 위치를 갖는 부모의 이름 속성을 얻기위한
가능한 중복 [XPath는 : 가져 오기 자식 노드가 속성을 포함 노드 ] (http://stackoverflow.com/questions/1457638/xpath-get-nodes-where-child-node-contains-an-attribute) –
@Ansgar - 아닙니다. 속성은 결과 집합을 제한하지 않습니다. –
@ Ekkehard.Horner 그의 경우 표현식은 속성 ('// User [Element/AdditionalInfo/Location/text() = 'Local']') 대신 텍스트 노드를 비교해야하지만, 많은 중복 된 AFAICS. –