Closed javadev closed 3 years ago
This is an example how to transform xml.
String xml =
"<some_root>\n"
+ " <ABC some_attribute=\"attribute\">\n"
+ " <another_tag>some_value</another_tag>\n"
+ " </ABC>\n"
+ "</some_root>";
Map<String, Object> data = U.fromXmlMap(xml);
U.set(data, "some_root.ABC.#text", U.get(data, "some_root.ABC.another_tag"));
U.remove(data, "some_root.ABC.another_tag");
String newXml = U.toXml(data);
assertEquals("<some_root>\n" +
" <ABC some_attribute=\"attribute\">some_value</ABC>\n" +
"</some_root>", newXml);
I hope it's not a duplicated question, I was looking for an answer for my simple question but I couldn't find anything. I need to convert json to xml using the underscore java library and this is quite easy using U.jsonToXml method. My problem is when I need to create node with value and attribute.
What I can do:
What I need is:
I was trying different things, playing around with arrays or with self-closing-tag, looking at the gh repo but I couldn't get the node with parameters and value:
Is there any way to do this? Thanks for your help.