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

XML Finding and displaying children nodes

Status
Not open for further replies.

TorMag

Programmer
Jun 26, 2007
4
US
Hi, been a real long time since I have worked in ASP and XML and a neighbor asked me to help him with a web page. I have an XML file that I am trying to search thru and display the children nodes......

Here is a sample of the xml

<document>
<MEMBER>
<ID>000-00-0010</ID>
<CHARGES>
<CHARGE><ChargeDate>06/25/2007</ChargeDate><Code>BANQ</Code><Desc>BANQUET</Desc><Amount>0.00</Amount><Note></Note></CHARGE>
<CHARGE><ChargeDate>06/25/2007</ChargeDate><Code>OSR</Code><Desc>RENT</Desc><Amount>0.00</Amount><Note></Note></CHARGE>
<CHARGE><ChargeDate>06/25/2007</ChargeDate><Code>PR</Code><Desc>POSTAGE REIMBUR</Desc><Amount>0.00</Amount><Note></Note></CHARGE>
<CHARGE><ChargeDate>06/25/2007</ChargeDate><Code>YBS</Code><Desc>YRBK SPONSOR</Desc><Amount>0.00</Amount><Note></Note></CHARGE>
<CHARGE><ChargeDate>06/25/2007</ChargeDate><Code>ZA</Code><Desc>ADMIN.FEE</Desc><Amount>0.00</Amount><Note></Note></CHARGE>
</CHARGES>
<PAYMENT>
<PaymentDate></PaymentDate><PaymentAmount>0.00</PaymentAmount>
</PAYMENT>
</MEMBER>
<MEMBER>
<ID>000-00-0011</ID>
<CHARGES>
<CHARGE><ChargeDate>06/25/2007</ChargeDate><Code>PC</Code><Desc>SICK COMPER CAP</Desc><Amount>558.00</Amount><Note>10/31/2004</Note></CHARGE>
<CHARGE><ChargeDate>06/25/2007</ChargeDate><Code>ZA</Code><Desc>ADMIN.FEE</Desc><Amount>16.74</Amount><Note></Note></CHARGE>
</CHARGES>
<PAYMENT>
<PaymentDate></PaymentDate><PaymentAmount>0.00</PaymentAmount>
</PAYMENT>
</MEMBER>
<MEMBER>
<ID>000-00-0012</ID>
<CHARGES>
<CHARGE><ChargeDate>06/25/2007</ChargeDate><Code>ZA</Code><Desc>ADMIN.FEE</Desc><Amount>0.00</Amount><Note></Note></CHARGE>
</CHARGES>
<PAYMENT>
<PaymentDate></PaymentDate><PaymentAmount>0.00</PaymentAmount>
</PAYMENT>
</MEMBER>
</document>


I have put together this XLS file

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="<xsl:template match="/">
<h1>Charges</h1>
<table cellpadding="3" cellspacing="0">
<tr>
<th>Charge Date</th>
<th>Charge Code</th>
<th>Description</th>
<th>Amount</th>
<th>Note</th>
</tr>
<xsl:apply-templates select="//CHARGE"/>
</table>
</xsl:template>
<xsl:template match="CHARGE">
<tr>
<td><xsl:value-of select="ChargeDate" /></td>
<td><xsl:value-of select="Code" /></td>
<td><xsl:value-of select="Desc" /></td>
<td><xsl:value-of select="Amount" /></td>
<td><xsl:value-of select="Note" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>

What I am trying to do is display the charges for say ID = 000-00-0010

Here is the VB script I am trying to use.....

function transformDetailXML( XML, XSL, strDetail )
Dim objXML
Dim objXSL
Dim objNode
'dim objCharges

Set objXML = getXMLDoc(XML)
Set objNode = objXML.SelectSingleNode("document/MEMBER/ID/[text()='" & strDetail & "']")
'Set objCharges = objNode.selectNodes("/CHARGES[CHARGE]")

Set objXSL = getXMLDoc(XSL)
If objXML.parseError <> 0 Then Response.Write reportParseError(objXML.parseError)
If objXSL.parseError <> 0 Then Response.Write reportParseError(objXSL.parseError)

transformDetailXML = objNode.transformNode(objXSL)
End Function

And lastly, this is what is showing in my browser....

Searching Mode
<ID>000-00-0010</ID>

Thanks in advance for your help.....
 
Haven't attempted to read all those. But this is wrong.
>Set objNode = objXML.SelectSingleNode("document/MEMBER/ID/[text()='" & strDetail & "']")
[tt]Set objNode = objXML.SelectSingleNode("document/MEMBER/I[highlight]D[[/highlight]text()='" & strDetail & "']")[/tt]
 
Thank you tsuji, already new about that, forgot to take that out when I posted... was trying something else to get it to work....but that's not it....
 
When you say
What I am trying to do is display the charges for say ID = 000-00-0010

Do you mean all this information??

Code:
<CHARGE><ChargeDate>06/25/2007</ChargeDate><Code>BANQ</Code><Desc>BANQUET</Desc><Amount>0.00</Amount><Note></Note></CHARGE>
<CHARGE><ChargeDate>06/25/2007</ChargeDate><Code>OSR</Code><Desc>RENT</Desc><Amount>0.00</Amount><Note></Note></CHARGE>
<CHARGE><ChargeDate>06/25/2007</ChargeDate><Code>PR</Code><Desc>POSTAGE REIMBUR</Desc><Amount>0.00</Amount><Note></Note></CHARGE>
<CHARGE><ChargeDate>06/25/2007</ChargeDate><Code>YBS</Code><Desc>YRBK SPONSOR</Desc><Amount>0.00</Amount><Note></Note></CHARGE>
<CHARGE><ChargeDate>06/25/2007</ChargeDate><Code>ZA</Code><Desc>ADMIN.FEE</Desc><Amount>0.00</Amount><Note></Note></CHARGE>

This is what I see to do:

Code:
Set objNode = objXML.SelectSingleNode("document/MEMBER/ID[text()='" & strDetail & "']/CHARGES")
Set objCharges = objNode.getElementsByTagName("CHARGE")

//From there, loop through each CHARGE and extract the data, if you have questions, feel free to ask.


[monkey][snake] <.
 
Thanks Monksnake,

Yes, that is the data I am trying to display.... What changes do I need to make to the XLS file so that the results are then displayed?

Thanks
 
What changes do I need to make to the XLS file so that the results are then displayed?

To be honest, I really don't know. I know super little about XLS. tsuji would be the person to ask about this. I recommend posting in the XML forum.

[monkey][snake] <.
 
Thanks guys, but this was an ASP question and I finally managed to solve it with straight VBScript...


xmlDoc = "exporting.xml"

strDetail = "000-00-0010"


Set objXML = getXMLDoc(xmlDoc)
Set objNodeList = objXML.getElementsByTagName("document/MEMBER[ID='" & strDetail & "']/CHARGES/CHARGE")


numberofitems = objNodeList.length


For i = 0 To numberofitems - 1

Set objHdl = objNodeList.item(i)
Response.Write objHdl.childNodes(0).text & " " & objHdl.childNodes(1).text & " " & objHdl.childNodes(2).text & " " & objHdl.childNodes(3).text & " " & objHdl.childNodes(4).text & "<br>"

Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top