daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Oct 23rd, 2018 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 1.<link-protection/>
  2.  2.<undocumented><lcd>
  3.  3. <message>
  4.        *****{with escape characters}</message>
  5.  4.<xyz comment= "**hshhshs">, and more
  6.    
  7. <root>
  8.   <id>1</id>
  9.   <title>mytitle</title>
  10. </root>
  11.    
  12. import com.fasterxml.jackson.databind.node.ObjectNode;
  13. import com.nerdforge.unxml.Parsing;
  14. import com.nerdforge.unxml.factory.ParsingFactory;
  15. ...
  16.  
  17. public class MyController {
  18.     public ObjectNode getJsonFromXml(String inputXmlString) {
  19.         Parsing parsing = ParsingFactory.getInstance().create();
  20.         Document document = parsing.xml().document(inputXmlString);
  21.  
  22.         Parser<ObjectNode> parser = parsing.obj("root")
  23.           .attribute("id", "id", parsing.number()) // uses a number parser
  24.           .attribute("title") // both xpath and json-attribute-key is "title"
  25.           .build();
  26.  
  27.         ObjectNode node = parser.apply(document);
  28.         return node;
  29.     }
  30. }
  31.    
  32. {
  33.   "id":1,
  34.   "title":"mytitle"
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top