XML Newbie:Can this Be Done

Scott Boucher

Usenet Archive
Joined
Feb 13, 2004
Messages
2
Reaction score
0
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>
 

Unregistered

Usenet Archive
Joined
Jul 1, 2003
Messages
28
Reaction score
0
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
 

Patrick TJ McPhee

Usenet Archive
Joined
Apr 2, 2000
Messages
269
Reaction score
0
[...]

% 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
 

Scott Boucher

Usenet Archive
Joined
Feb 13, 2004
Messages
2
Reaction score
0
It Looks Great, but how did you do it. Parsed it with what. Also do not want the data tag <ITEM#>

Thanks
 

Tripredacus-X

Usenet Archive
Joined
Feb 8, 2004
Messages
11
Reaction score
0
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

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,802
Members
249,594
Latest member
henrywalsh

Latest Threads

Top