XML Newbie:Can this Be Done

S

Scott Boucher

I have an XML document that looks like this:

- <MSG>
- <HDR_DATA>
<DATE>20040211</DATE>
<STORE_NUM>2210</STORE_NUM>
<REG_NUM>5</REG_NUM>
<TRANS_NUM>1234</TRANS_NUM>
</HDR_DATA>
- <DTAIL_DATA>
<CODE>222222</CODE>
<SIGN_FLG>0</SIGN_FLG>
<QTY>222222</QTY>
</DTAIL_DATA>
- <DTAIL_DATA>
<CODE>333333</CODE>
<SIGN_FLG>0</SIGN_FLG>
<QTY>333333</QTY>
</DTAIL_DATA>
- <DTAIL_DATA>
<CODE>444444</CODE>
<SIGN_FLG>1</SIGN_FLG>
<QTY>444444</QTY>
</DTAIL_DATA>
</MSG>

I want the XML Document to Look Like This:(Essentially, I want
HDR_DATA to appear with each DTAIL_DATA)

- <MSG>
<DTAIL_DATA>
<DATE>20040211</DATE>
<STORE_NUM>2210</STORE_NUM>
<REG_NUM>5</REG_NUM>
<TRANS_NUM>1234</TRANS_NUM>
<CODE>222222</CODE>
<SIGN_FLG>0</SIGN_FLG>
<QTY>222222</QTY>
</DTAIL_DATA>

<DTAIL_DATA>
<DATE>20040211</DATE>
<STORE_NUM>2210</STORE_NUM>
<REG_NUM>5</REG_NUM>
<TRANS_NUM>1234</TRANS_NUM>
<CODE>333333</CODE>
<SIGN_FLG>0</SIGN_FLG>
<QTY>333333</QTY>
</DTAIL_DATA>

<DTAIL_DATA>
<DATE>20040211</DATE>
<STORE_NUM>2210</STORE_NUM>
<REG_NUM>5</REG_NUM>
<TRANS_NUM>1234</TRANS_NUM>
<CODE>444444</CODE>
<SIGN_FLG>1</SIGN_FLG>
<QTY>444444</QTY>
</DTAIL_DATA>
</MSG>
 
U

Unregistered

It parses without error. I edited it to remove redundancy. How does thi
look?

<?xml version="1.0"?>
<MSG>
<DTAIL_DATA>
<DATE>20040211</DATE>
<STORE_NUM>2210</STORE_NUM>
<REG_NUM>5</REG_NUM>
<TRANS_NUM>1234</TRANS_NUM>
<ITEM1>
<CODE>222222</CODE>
<SIGN_FLAG>0</SIGN_FLAG>
<QTY>222222</QTY>
</ITEM1>
<ITEM2>
<CODE>333333</CODE>
<SIGN_FLG>0</SIGN_FLG>
<QTY>333333</QTY>
</ITEM2>
<ITEM3>
<CODE>444444</CODE>
<SIGN_FLG>1</SIGN_FLG>
<QTY>444444</QTY>
</ITEM3>
</DTAIL_DATA>
</MSG

Unregistered
 
P

Patrick TJ McPhee

[...]

% I want the XML Document to Look Like This:(Essentially, I want
% HDR_DATA to appear with each DTAIL_DATA)

Using xslt, use a template like this

<xsl:template match='MSG'>
<DTAIL_DATA>
<xsl:copy-of select='HDR_DATA/*|DTAIL_DATA/*'/>
</DTAIL_DATA>
</xsl:template
 
S

Scott Boucher

It Looks Great, but how did you do it. Parsed it with what. Also do
not want the data tag <ITEM#>

Thanks
 
T

Tripredacus-X

Scott said:
It Looks Great, but how did you do it. Parsed it with what. Als
do
not want the data tag <ITEM#>

Thanks


Well i just noticed the redundancy and determined a more compact way o
displaying the same data. The smaller the file the faster it processes
Remember that there are many ways of displaying the same data, whethe
it be more fleshed out like yours or more compact like mine.

I used the <ITEM#> tag as a placeholder for whatever tag name yo
wanted to use. I used it just as an example.

As for -how- I did it... I noticed that a lot of data values wer
repeated:

<DATE>20040211</DATE>
<STORE_NUM>2210</STORE_NUM>
<REG_NUM>5</REG_NUM>
<TRANS_NUM>1234</TRANS_NUM>

So I consolidated this into one entry and created child elements fo
the data that was different. If there were two different dates, stor
numbers, etc I would have had to reorganise it differently.

But I don't see where the "'HDR_DATA" comes into play..

Tripredacus-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,231
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top