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

Parsing XML and extracting Data

Status
Not open for further replies.

ppeel

Programmer
Dec 7, 2004
18
US
I need to extract specific data from an XML file that looks like this:

<?xml version="1.0" encoding="UTF-8" ?>
- <Transmission xmlns:xalan="- <ImageInfo SubscriberAMI="127100570" DCN="10173100150101" DateRecieved="20100622" AccountNumber="3330972" transmissionType="Send" ClaimEngineKey="201017477202308" ImageType="Claim" MemberSuffix="2" SubscriberSSN="123456789" EDI_Claim_Key="2010062389386201000088" ClaimEngineIdentifier="PRIC">
<ImageName value="10173100150101.tif" />
</ImageInfo>
- <ImageInfo SubscriberAMI="895929369" DCN="10200101450121" DateRecieved="20100719" AccountNumber="3330972" transmissionType="Send" ClaimEngineKey="201020077208151" ImageType="Claim" MemberSuffix="1" SubscriberAMI="987654321" EDI_Claim_Key="2010071996011901001340" ClaimEngineIdentifier="PRIC">
<ImageName value="10200101450121.tif" />
2010072697979101000119" ClaimEngineIdentifier="PRIC">
<ImageName value="10207101810061.tif" />
</ImageInfo>
</Transmission>

I need to extract the DCN, SubscriberSSN, SubscriberAMI, DateRecieved and the ImageName and write them to a text file.
I am having difficulty extracting the ImageName and writing it to the same line in the text file. What do I need to do to get the ImageName value?

Here is my vbscript:

xmlFileName = "p:\cigna_images\test\transmission.xml"

'DOM = Document Object Model
Set xmlDoc = CreateObject("MSXML2.DOMDocument.4.0")

WScript.Echo "Filename=" & xmlFileName

' Validate the document using the MSXML parser.
xmlDoc.load (xmlFileName)

' SelectNodes
set nodelist = xmlDoc.selectNodes("/Transmission/ImageInfo")

For Each node In nodelist
DCN=node.attributes.getnameditem("DCN").value
SubscriberSSN=node.attributes.getnameditem("SubscriberSSN").value
SubscriberAMI=node.attributes.getnameditem("SubscriberAMI").value
DateRecieved=node.attributes.getnameditem("DateRecieved").value
' Imagefile=node.attributes.getnameditem("ImageName").value
'
WScript.Echo DCN & "," & SubscriberSSN & "," & SubscriberAMI & "," & DateRecieved & "," & Imagefile
Next

WScript.Echo "The end"


Thanks for any help in advance.
 
For Each node In nodelist
'do you more than one? then you need SelectNodes and loop?
Set xmlImageName = node.SelectSingleNode("ImageName")
'error trap if there isnt an ImageName..here
ImageFile = xmlImageName.innerText? or .Text i can never remember
Set xmlImageName = Nothing
Next
 
If you just want a quick shot of getting data, you can do this.
[tt]
' Imagefile=node.attributes.getnameditem("ImageName").value
Imagefile=node.firstchild.attributes.getnameditem("value").value
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top