getting attributes from XML

miraclebabycaw

New Member
Hi all

wonder if you can all help. I'm very new to XML. I need to create and XML and then receive a reply back, use the values in the reply to create data in our DB. Here is a sample of the reply (I have successfully generated the request)

<DOCUMENT.......> /* level 0? */
<TX sp_bhf="999" tx_nbr="9999"> /* level 1? */
<NW pc_nbr="01"> /* level 2? */
<FIN nett="99.99"> /* level 2? */
<SURCH schm="10.00"> /* level 3? */
</FIN> /* level 2? */
<ITEM nbr="1"> /* level 2? */
<FIN nett="569.90"> /* level 3? */
<SURCH schm="10.00"> /* level 4? */
</FIN> /* level 3? */
<REF cd="000000001"> /* level 3? */
<FIN price="70.56> /* level 4? */
<FEE prof=14.11"> /* level 5? */
</FIN>
</REF>
</ITEM>
</TX>
</DOCUMENT>

How do I go about getting the values of the attributes to assign them to the relevant fields in my temp-table. Please remember I am very new to XML so please don't get too technical :confused:

Thanks
 

FrancoisL

Member
Your XML file you show here is invalide.

A Xml require a Opening and closing tag much like HTML.


This is valid:
<TAG1>
<TAG2>
</TAG2>
</TAG1>

This is invalid:
<TAG1>
<TAG2>
</TAG1>
</TAG2>

Example from your xml:

<FIN nett="99.99"> // FIN is Openned
<SURCH schm="10.00"> // SURCH is openned
</FIN> // FIN is Closed but SURCH has not been closed .

It should be :
<FIN nett="99.99">
<SURCH schm="10.00"> </SURCH>
</FIN>

or (better pratice)

<FIN nett="99.99">
<SURCH schm="10.00" /> /* ending a tag with /> means it closed.
</FIN>

It should be easier for a Xml parser if the Xml is well formed.
 

miraclebabycaw

New Member
Hi thanks. Ok yes I probably just copied it incorrectly. Assume it is all closed correctly as it will come in correct. The question is how to I get the info from the attributes
 

tamhas

ProgressTalk.com Sponsor
you don't mention version, but with any vaguely recent version you have your choice of DOM or SAX. I think SAX is the better approach, especially for large documents, because DOM requires loading the whole document in memory while SAX does it in a streaming fashion.

Describing how to do either one is a rather large task for a forum answer, so I recommend that you tackle the manuals, experiment some, and then come back with questions about any mysteries.

For some sample SAX-READER code you can look at the core package here http://www.oehive.org/node/900
 
Top