cancel
Showing results for 
Search instead for 
Did you mean: 

Creating index in Headers and Lines

david_fryda2
Participant
0 Kudos

Hi everyone,

I have the following XML.

<header>

     <key/>

     <dummy1/>

</header>

<line>

     <key/>

     <dummy2/>

</line>

I want to populate a counter/index in field key of header and line.

A header can have many lines.

In the XML file, there can be many headers.

the header and lines are connected via field key.

Example:

<header>

     <key>1</key>

     <dummy1>abcd</dummy1>

</header>

<line>

     <key>1</key>

     <dummy2>aaaa</dummy2>

</line>

<line>

     <key>1</key>

     <dummy2>bbbbb</dummy2>

</line>

<header>

     <key>2</key>

     <dummy1>abcd</dummy1>

</header>

<line>

     <key>2</key>

     <dummy2>eeee</dummy2>

</line>

<line>

     <key>2</key>

     <dummy2>rrrr</dummy2>

</line>

<line>

     <key>2</key>

     <dummy2>qqqq</dummy2>

</line>

I tried to use the INDEX or COUNT in Message Mapping but I did not succeed.

Can someone help ?

Thanks,

Regards.

Accepted Solutions (0)

Answers (3)

Answers (3)

JaySchwendemann
Active Contributor
0 Kudos

I'm not sure I'm following (completely).

1. Please give an example of your input and an example of the desired output.

2. Please state, what's your scenario. Is it File (Flat File) --> PI --> <Target>?

FCC is File Content Conversion by the way, some technique to make an XML document out from a flat file. Headers and items are supported with FCC.

HTH

Cheers

Jens

david_fryda2
Participant
0 Kudos

Input flat file:

HMetallica

LNothing else matters

LEnter Sandman

HACDC

LHighway to hell

LBack in black


The target XML file looks like:

<header>

<band>Metallica</band>

</header>

<header>

<band>ACDC</band>

</header>

<line>

<title>Nothing else matters</title>

</line>

<line>

<title>Enter Sandman</title>

</line>

<line>

<title>Highway to hell</title>

</line>

<line>

<title>Back in black</title>

</line>

The order is changed. So I want to create a key between headers and lines thus I can regroupe them later.

The desired XML target file would be:

<header>

<band>Metallica</band>

<key>1</key>

</header>

<header>

<band>ACDC</band>

<key>2</key>

</header>

<line>

<title>Nothing else matters</title>

<key>1</key>

</line>

<line>

<title>Enter Sandman</title>

<key>1</key>

</line>

<line>

<title>Highway to hell</title>

<key>2</key>

</line>

<line>

<title>Back in black</title>

<key>2</key>

</line>

Thanks,

Regards.

former_member182412
Active Contributor
0 Kudos

Hi David,

By looking at your requirement i think you can do as per this blog If you follow the blog you no need key fields, if not let me know.

Regards,

Praveen.

david_fryda2
Participant
0 Kudos

Hi Praveen,

I look at the example but I do not understand what I must do exactly.

Regards.

JaySchwendemann
Active Contributor
0 Kudos

So finally there's someone with a taste for good music

Anyways: If I get you correctly, you have an input flat file that already has an order which groups together bands and titles, right?

Why do you need the "target XML file" to be flat as well? You could, as Praveen has shown in the link, instantly create a deep nested XML after (graphical) mapping without the need for keys, like so:


<document>

    <band>

        <bandName>Metallica</bandName>

        <title>Nothing else matters</title>

        <title>Enter Sandman</title>

    </band>

    <band>

        <bandName>ACDC</bandName>

        <title>Highway to hell</title>

        <title>Back in black</title>

    </band>

</document>

If you need to obey the root structure of the "target XML file" and only could add nodes on a sub-node level (like the "key" node you introduced), then only you would need to go through the troubles of computing a key field.

Cheers

Jens

engswee
Active Contributor
0 Kudos

Hi David

Firstly, from your example XML, it looks like it isn't a well-formed XML. <header> and <line> are at the same level so you cannot have them interleaved like below:-

<header>

<line>

<header>

<line>

<line>

A well-formed XML will have all the <header> before all the <line>.

How is your XML generated? It is from an FCC configuration?

Secondly, it this XML structure the source or the target? What is the logic to determine the value of the index/counter? Is it by position?

Regards

Eng Swee

david_fryda2
Participant
0 Kudos

Hi Eng Swee,

The headers are like subheaders.

The xml generated is like what I described in my first post but all the headers are grouped together (and so the lines).

The purpose is to create a key between the headers and their own lines.

It is from an FCC configuration? Sorry, I do not know what is FCC.


Thanks.


Regards.

konrad_thalheim3
Active Participant
0 Kudos

Hi David,

I suggest you use a variable on header level and populate it with the Index and SplitByValue functions.

Like this - just without the concatenation:

See also:

Standard Functions in PI 7.0 - Process Integration - SCN Wiki

Kind regards

Konrad

david_fryda2
Participant
0 Kudos

Hi Konrad,

The example you sent is using count.

I tried to use index instead but get error like "Values missing in queue context".

Thanks.

Regards.