cancel
Showing results for 
Search instead for 
Did you mean: 

Xml Manipulation

Former Member
0 Kudos

Hi Rick,

The input file is :-

<?xml version="1.0" encoding="UTF-8"?><CampaignDetails><CampaignID> </CampaignID><CampaignID> 2</CampaignID><CampaignID> 3</CampaignID>

<CampaignID>4</CampaignID><StartTime CampaignID="1"> st1</StartTime>

<StartTime CampaignID="2"> st2</StartTime><StartTime CampaignID="3"> st3</StartTime><StartTime CampaignID="4">st4</StartTime><EndTime CampaignID="1">et1</EndTime><EndTime CampaignID="2">et2</EndTime>

<EndTime CampaignID="3">et3</EndTime> <EndTime CampaignID="4">et4</EndTime><Description CampaignID="1"> This is Campaign 1</Description><Description CampaignID="2"> This is Campaign 2</Description><Description CampaignID="3"> This is Campaign 3</Description>

<Description CampaignID="4"> This is Campaign 4</Description></CampaignDetails>

Desirable output is :-

<Location><CampaignDetails><Campaign> <ID>1</ID><Description>This is Campaign 1</Description><StartTime>st1</StartTime><EndTime>et1</EndTime>

</Campaign><Campaign><ID>2</ID><Description>This is Campaign 2</Description><StartTime>st2</StartTime><EndTime>et2</EndTime>

</Campaign></CampaignDetails><CampaignDetails><Campaign><ID>3</ID>

<Description>This is Campaign 3</Description><StartTime>st3</StartTime>

<EndTime>et3</EndTime></Campaign><Campaign><ID>4</ID>

<Description>This is Campaign 4</Description><StartTime>st4</StartTime>

<EndTime>et4</EndTime></Campaign></CampaignDetails></Location>

Right now, two campaigns has to go in a grouping of CampaignDetails. Requirement may vary later.

Thanks in Advance,

Lipsa.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

OK, then - now we have enough information to provide some guidance.

Start with your previous transaction, and we'll make some modifications.

1. Let's add another transaction input called 'GroupSize", of type integer, and let's give it a value of 2.

2. Let's also add another Local property of type XML, called "Location", and give it an initial value of:

<Location/>

3a. After the sequence/action in which you assigned the individual fields of the Campaign element, add a new sequence with a Conditional action.

3b. Delete the sequence containing the "append xml" link where you were appending individual Campaign items to the CampaignDetails element. We'll replace this with something else in a few moments.

4. Assign an input link to the Input1 property of the Conditional, with the following expression (which will trigger the "true" sequence each "GroupSize" items):

((CampaignRepeater.CurrentItem % Transaction.GroupSize) == 1)

5. Add three child sequences to this conditional (one for the true, one for false, one for "always").

6. Add an an assignment action of type "Append Xml" to the first child sequence below the conditional (the "true" branch) with the following target and expression:

Target: Local.Location{/Location}

Expression: Local.CampaignDetails

This will append an empty CampaignDetails element to the Location element each time a new set of "GroupSize" items are encountered.

7. Add an assignment action of type "Append Xml" to the last child sequence below the conditional (the "always" branch) with the following target and expression:

Target: Local.Location{/Location/CampaignDetails[position() = last()]}

Expression: Local.Campaign{/Campaign}

This assignment will always append the Campaign item to the most recently added CampaignDetails element - this is the effect of position() = last().

You owe me 1000 points now.

- Rick

Former Member
0 Kudos

Hi Rick,

I got the desirable output.

Well, I know I owe you even more than a 1000 points.

But, I have awarded the max 10 points. You have to be happy in this only.

Hey, I had doubt at few places. I could not properly understand the steps 4 and 7,

which are infact, the turning points of the whole transaction. Can you just explain me in detail, as to what exactly these two steps do?

Thanks,

Lipsa.

Former Member
0 Kudos

Step #4 is to append a new CampaignDetails element to the Location element each time a new "group" is started. To do so, it uses the modulus operator (%) to determine this. The conditional action can have any number of boolean input conditions, but in this case, we only needed one. If it is the "first one of the group".

Step #7 uses an XPath syntax to select (as the target for the Append Xml link) the last CampaignDetails element, to which the Campaign element is appended.

- Rick

Former Member
0 Kudos

Hi Rick,

I want an output to look like :-

<?xml version="1.0" encoding="UTF-8"?>

<MaterialInformation xmlns="http://www.wbf.org/xml/b2mml-v0201">

<Location>

<EquipmentID>1000</EquipmentID>

<EquipmentElementLevel OtherValue="String">Plant</EquipmentElementLevel>

</Location>

<PublishedDate>2000-01-01T00:00:00</PublishedDate>

<MaterialClass>

<ID>01</ID>

<Description>HALB</Description>

</MaterialClass>

<MaterialClass>

<ID>01</ID>

<Description>FERT</Description>

</MaterialClass>

<MaterialDefinition>

<ID>000000000000000005</ID>

<Description>Formaldehyde</Description>

<MaterialClassID>01</MaterialClassID>

</MaterialDefinition>

<MaterialDefinition>

<ID>000000000000000009</ID>

<Description>Protein Solution 100</Description>

<MaterialClassID>01</MaterialClassID>

</MaterialDefinition>

</MaterialInformation>

But I am getting it like :-

<?xml version="1.0" encoding="UTF-8"?>

<MaterialInformation xmlns="http://www.wbf.org/xml/b2mml-v0201">

<Location>

<EquipmentID>1000</EquipmentID>

<EquipmentElementLevel OtherValue="String">Plant</EquipmentElementLevel>

</Location>

<PublishedDate>2000-01-01T00:00:00</PublishedDate>

<MaterialClass>

<ID>01</ID>

<Description>HALB</Description>

</MaterialClass>

<MaterialDefinition>

<ID>000000000000000005</ID>

<Description>Formaldehyde</Description>

<MaterialClassID>01</MaterialClassID>

</MaterialDefinition>

<MaterialClass>

<ID>01</ID>

<Description>FERT</Description>

</MaterialClass>

<MaterialDefinition>

<ID>000000000000000009</ID>

<Description>Protein Solution 100</Description>

<MaterialClassID>01</MaterialClassID>

</MaterialDefinition>

</MaterialInformation>

How should I achieve this?

Thanks in Advance,

Lipsa.

Former Member
0 Kudos

I see you're using B2MML/S95!

When you are appending your XML elements for MaterialClass and MaterialDefinition, do the following:

If it is the first MaterialClass or first MaterialDefinition, you'll use an "Append XML" link and the target will be the /ns1:MaterialInformation element.

If it is not the first item, you'll use an "Append After XML" link, and the target will be something similar to /ns1:MaterialInformation/ns1:MaterialClass for the new MaterialClass element and /ns1:MaterialInformation/ns1:MaterialDescription for the new MaterialDescription element.

As with the previous example, you can use a conditional expression along with the CurrentItem property of a repeater action to determine whether you are appending the first item or not.

Rick

Former Member
0 Kudos

Hi Rick,

I have taken two transaction variables of xml type, one for MaterialClass and another for MaterialDefinition.

I have taken two Repeaters. In one, i am repeating MaterialClass, and in the other, MaterialDefinition.

Each Repeater is followed by one condition.

I have the condition as

Target/Assignment

1. (RepeatMaterialClass.CurrentItem==0) --> ForFirstMaterialClass.Input1

2. (RepeatMaterialDefinition.CurrentItem==0) --> ForFirstMaterialDefinition.Input1

Then I am appending as you said.

Still not getting the output. Is the process correct?

Please reply soon.

Thanks,

Lipsa.

Former Member
0 Kudos

Can't really provide much more help on such limited information. You'll have to work this one out.

Answers (0)