Expand my Community achievements bar.

SOLVED

Add New Record to XML

Avatar

Former Community Member

I'm having issues inserting a new record into an exisiting XML variable. 

For example I already have an XML variable with two records:

<UserData>

     <UserInfo>

          <Name>Jim</Name>

          <Phone>111-111-1111</Phone>

     </UserInfo>

     <UserInfo>

          <Name>Mike</Name>

          <Phone>222-222-2222</Phone>

     </UserInfo>

</UserData>

Now if I wanted to add a third record:

<UserData>

     <UserInfo>

          <Name>Sam</Name>

          <Phone>333-333-3333</Phone>

     </UserInfo>

</UserData>

I've tried a couple of things in the XPath Builder...I know you can reference each record by an index number, but I don't find any functions for adding the Record

Anyone have any suggestions on how to handle this?

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

This is far more difficult than you might imagine since XPath and XSLT do not support the notion of insertion.

You are left to write a Custom Script or create a utility service that can be re-used. The process for that utility service would look like this...

p.png

I parse the XML to extract each <UserData>, add the string to a List of strings, add the new user to the end of the List, parse the List to build an xml string, and finally serialize the xml string to xml. Ugly but true.

If you would like a copy of the .lca, please send an email to stwalker.adobe@gmail.com.

Steve

View solution in original post

8 Replies

Avatar

Correct answer by
Former Community Member

This is far more difficult than you might imagine since XPath and XSLT do not support the notion of insertion.

You are left to write a Custom Script or create a utility service that can be re-used. The process for that utility service would look like this...

p.png

I parse the XML to extract each <UserData>, add the string to a List of strings, add the new user to the end of the List, parse the List to build an xml string, and finally serialize the xml string to xml. Ugly but true.

If you would like a copy of the .lca, please send an email to stwalker.adobe@gmail.com.

Steve

Avatar

Level 2

Steve,

Is it possible to send me the lca which resolves adding a new record to an xml variable in workbench?

Or are there in the meanwhile better solutions to this problem? I've already sent an email but got no reply and it's pretty urgent.

Thanks in advance!

With kind regards,

Kristof Rasschaert

Avatar

Level 10

Or, you could create a custom component that does all that xml manipulation.

This would make you process a bit cleaner.

Jasmin

Avatar

Level 2

Can I please still get the LCA? It's urgent and I'm not a good

java coder at all!

But is this link (http://www.adobe.com/devnet/livecycle/articles/dsc_development.html) a good start for making your own components?

Thanks

Kristof

Avatar

Level 10

Yes. That's a good start.

Steve is on the west coast (US), so he'll get online in a few hours.

Jasmin

Avatar

Level 2

Thanks a lot Jasmin!

I have another problem, maybe you know a solution.

I've already posted it on the forum but got no replies, you can find it here: http://forums.adobe.com/thread/617825?tstart=0

It's about the data from a pdf getting lost after flattening.

Can you take a look at it?

Thanks

Kristof

Avatar

Former Community Member

The process has two inputs, as shown below, and produces an output xml data type that inserts the new user.

1) inputXml

<UserData>

     <UserInfo>

          <Name>Jim</Name>

          <Phone>111-111-1111</Phone>

     </UserInfo>

     <UserInfo>

          <Name>Mike</Name>

          <Phone>222-222-2222</Phone>

     </UserInfo>

</UserData>

2) newUser

<UserData>

     <UserInfo>

          <Name>Sam</Name>

          <Phone>333-333-3333</Phone>

     </UserInfo>

</UserData>

The .xml and the .lca are attached.

Steve

Avatar

Level 2

Thanks Steve!! I got it working.

Kristof

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----