Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.<link-protection/>
- 2.<undocumented><lcd>
- 3. <message>
- *****{with escape characters}</message>
- 4.<xyz comment= "**hshhshs">, and more
- <root>
- <id>1</id>
- <title>mytitle</title>
- </root>
- import com.fasterxml.jackson.databind.node.ObjectNode;
- import com.nerdforge.unxml.Parsing;
- import com.nerdforge.unxml.factory.ParsingFactory;
- ...
- public class MyController {
- public ObjectNode getJsonFromXml(String inputXmlString) {
- Parsing parsing = ParsingFactory.getInstance().create();
- Document document = parsing.xml().document(inputXmlString);
- Parser<ObjectNode> parser = parsing.obj("root")
- .attribute("id", "id", parsing.number()) // uses a number parser
- .attribute("title") // both xpath and json-attribute-key is "title"
- .build();
- ObjectNode node = parser.apply(document);
- return node;
- }
- }
- {
- "id":1,
- "title":"mytitle"
- }
Add Comment
Please, Sign In to add comment