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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB script and XML

Status
Not open for further replies.

Kocky

Programmer
Oct 23, 2002
357
NL
Hello there,

Is there anyone out there who has experience in browsing through an XML document using VB script ?

What I want is to browse through all records within a certain segment.
I want to select segment "E1EDP01" and browse through all
items within this segment in a for loop construction.
The XML layout is like this:

TOP_SEG
E1DP01
E1DP02

The segment E1DP01 is on the same level as TOP_SEG. It is not a child of TOP_SEG.
We tried the following code but is does not work:

set segHeader = theIDoc.Segments.Top
set SegCurrent = segHeader.NextSibling("E1EDP01")
for each SegCurrent in segHeader.NextTwin("E1EDP01")
set Werks = SegCurrent("WERKS")
next


The XML comes from a SAP system (IDOC ORDERS05) and we need to parse it.

Hope someone can help me.

Greetings,

Pascal.

 
Here is an example of an XML that I parse:
Code:
<Install LastMod="2004129" Owner="tomthumbkop">
    <Name>Sample</Name>
    <Location>C:\Scripts\Mine\InstallRunner</Location>
    <Command>test.vbs</Command>
    <Process></Process>
    <Verification>
        <Type>MSI</Type>
        <Value>Blah</Value>
    </Verification>
    <FailureLevel>1</FailureLevel>
    <HasRun>False</HasRun>
</Install>
Here is the code that I use to get the value of the name tag:
[/code]
Function GetName(strXml)
Dim xmlDoc 'The config file
Dim NodeList 'Generic Node List
Dim Node 'Generic XML Node object
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False
xmlDoc.Load(strXml)
Set NodeList = xmlDoc.getElementsByTagName("Name")
For Each Node In NodeList
GetName = Node.text
Set Node = Nothing
Next
Set xmlDoc = Nothing
End Function 'GetName(strXml)
[/code]
In your case, once you have the node you want, you would need to get a collection of its children then For...Each through them processing each one.


[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
The normal way of handling the children of an element is to use the SelectNodes method on the document element of the DOMDocument object:

Code:
Dim lElements as MSXML2.IXMLDOMNodeList
Dim lElement as MSXML2.IXMLDOMElement
' the following statement uses the XPath syntax to select
' only the Elements from the specified node
' it will ignore Attributes, Comments etc.
Set lElements = MyDOMDocument.DocumentElement.SelectNodes("E1EDP01")
For Each lElement in lElements
    ' oode to use the methods and properties of lElement
    ' as required

Next
 
I forgot that you are using vbscript but the solution remains the same apart from the Dim statements which don't need the data type.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top