Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Need help to parse xml string to populate drop down list

Avatar

Level 2

Here is my problem:

I have a hidden text field that contains text from an xml

<facilities>
<building>
  <name>Building A</name>
  <name>Building B</name>
  <name>Building C</name>
  <name>Building D</name>
  <name>Building E</name>
  <name>Building F</name>
  <name>Building G</name>
  <name>Building H</name>
</building>
</facilities>

My goal is to read this xml string with JavaScript to populate a drop down with the element(name) values. Does anyone know how to script that?

Attached is a sample .xdp

Cheers,

Jesse

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Here is a modified sample. I put the code on the button click so you can see it in operation .....you can put that code on the event that makes sense for you. I also added another field for showing the DOM (this is for debug purposes and you can remove this field if you want).

Paul

View solution in original post

12 Replies

Avatar

Former Community Member

It looks like the BBS is messing up zip files ....can you re-post it but save it as a PDF file ..or rename the extension to xxx

Paul

Avatar

Level 2

Still didn't work.

Here is a PDF.

Jesse

Avatar

Correct answer by
Former Community Member

Here is a modified sample. I put the code on the button click so you can see it in operation .....you can put that code on the event that makes sense for you. I also added another field for showing the DOM (this is for debug purposes and you can remove this field if you want).

Paul

Avatar

Level 2

Thank you so much! I've spent hours trying to figure this out. Much appreciated!!!

Avatar

Level 2

Ok, here is another issue. I'm getting the xml back from a web service and

the xml format is different from the example I provided (not as clean).

It appears that it is only taking the value of one node. Is there a way to make this work via script?

PDF is attached.

Thanks,

Jesse

Avatar

Former Community Member

Here is a modified sample .....I changed the for loop as well as the debug step to show the structure of the xml that is being loaded. Then you can see how the nodes.item is achieved.

Paul

Avatar

Level 2

Ahhh, I see now. Thank you so much, again!

Jesse

Avatar

Level 2

The text field in my example is data from a web service. Is there a way to "clear out" the data dom to allow new/different data from the web service?

I noticed that when try to add new xml data to the dom, it combines it with the old xml. I'm looking for a way to clear the dom and add new data.

Does this make sense?

Thanks,

Jesse

Avatar

Former Community Member

You may want to try the command xfa.host.resetData();

This will reset the entire form back to its original state. If you only want to reset specific fields, you can name them sperated by comas in between the round braces.

Paul

Avatar

Level 10

Jesse,

      Were you able to fix the issue of clearing the DOM and add new data with the XML from webservice?? I am getting the similar issue and looking for a solution..

Does anyone has any ideas how to fix this?

Thanks

Srini

************************* Your old post Begin *******************

The text field in my example is data from a web service. Is there a way to "clear out" the data dom to allow new/different data from the web service?

I noticed that when try to add new xml data to the dom, it combines it with the old xml. I'm looking for a way to clear the dom and add new data.

Does this make sense?

Thanks,

Jesse

************************* Your old post End *******************

Avatar

Level 2

Srini,

Did you try the example from the above thread?

"You may want to try the command xfa.host.resetData();

Thiswill reset the entire form back to its original state. If you only wantto reset specific fields, you can name them sperated by comas inbetween the round braces."

I did try the first command to reset the entire form and it worked.

Jesse

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] ----