Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello: I am trying to parse an x

Status
Not open for further replies.

shavon

Programmer
Jun 18, 2001
102
CA
Hello:

I am trying to parse an xml document using msxml. I am new to xml and I need help!!!

I want to loop through all the child nodes of the root node and create a text file for each "LogicalRecordType". Please show me how to iterate through the file. Thank you.

This is what I want to do:
<LogicalRecordType Type=&quot;A&quot;>
--
--
Loop and get everything in here
--
--
<\LogicalRecordType>
Move to next <LogicalRecordType Type=&quot;B&quot;>

Thank you.
<Purchase xmlns:xsi=&quot; xsi:noNamespaceSchemaLocation=&quot;c:\chris\xml\xml\bin\Purchase.xsd&quot;>
- <LogicalRecordType Type=&quot;A&quot;>
<MicrofilmLocatorPrefix>200307</MicrofilmLocatorPrefix>
</LogicalRecordType>
- <LogicalRecordType Type=&quot;B&quot;>
<LogicalRecordCount>000000002</LogicalRecordCount>
<AuthorizedSalesAgentInstitutionId>00177</AuthorizedSalesAgentInstitutionId>
<AuthorizedSalesAgentBranchId>000006</AuthorizedSalesAgentBranchId>
<AuthorizedProcessingAgentInstitutionId>00177</AuthorizedProcessingAgentInstitutionId>
<AuthorizedProcessingAgentBranchId>000006</AuthorizedProcessingAgentBranchId>
<BulkEmployeeApplicationId xsi:nil=&quot;true&quot; />
<DeliveryDestinationOfCertificates>23</DeliveryDestinationOfCertificates>
<PurchaseNumber>00000001</PurchaseNumber>
<PurchaseApplicationType>01</PurchaseApplicationType>
<--- more child nodes--->
</LogicalRecordType>
<----->more


Dim xmlDom As MSXML2.DOMDocument
Dim xmlNode As MSXML2.IXMLDOMNode
Dim xmlNodeList As MSXML2.IXMLDOMNodeList
Dim xmlNodeList2 As MSXML2.IXMLDOMNodeList
Dim xmlRoot As MSXML2.IXMLDOMElement
Dim xmlNode2 As MSXML2.IXMLDOMNode
Dim xmlNode3 As MSXML2.IXMLDOMNode
Dim xmlChildNodes As MSXML2.IXMLDOMNodeList
Dim xmlChildNode
Dim xmlChildNodeName
Set xmlDom = New MSXML2.DOMDocument
xmlDom.async = False

xmlDom.Load (&quot;c:\chris\purchase.xml&quot;)

Set xmlRoot = xmlDom.documentElement

Set xmlChildNodes = xmlRoot.childNodes
'Set xmlChildNodes = xmlDom.documentElement.childNodes
Set xmlNodeList = xmlRoot.selectNodes(&quot;LogicalRecordType&quot;)

For Each xmlRoot In xmlNodeList
For Each xmlChildNodeName In xmlChildNodes
Debug.Print (xmlChildNodeName.nodeName)
Next xmlChildNodeName
Next xmlRoot
 
Just out-of-my-head:

dim objDOM as MSXML2.DOMDocument
dim objNode as MSXML2.IXMLDOMNode

Set objDom = New MSXML2.DOMDocument

if objDom.Load (&quot;c:\chris\purchase.xml&quot;) then
for each objNode in objDom.SelectNodes (&quot;Purchase/LogicalRecordType[@Type='A'&quot;)
debug.print objNode.nodeName & &quot;: &quot; & objNode.Text
next
else
'oops
end if

set objDOM is nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top