fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.nio.charset.StandardCharsets;
  7.  
  8. import javax.xml.parsers.DocumentBuilder;
  9. import javax.xml.parsers.DocumentBuilderFactory;
  10.  
  11. import org.w3c.dom.Document;
  12. import org.w3c.dom.Node;
  13. import org.w3c.dom.NodeList;
  14.  
  15. /* Name of the class has to be "Main" only if the class is public. */
  16. class Ideone
  17. {
  18. public static void main (String[] args) throws java.lang.Exception
  19. {
  20. String xml = "<NameID>test@email<!--foobar-->.com</NameID>";
  21. DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
  22. documentBuilderFactory.setNamespaceAware(true);
  23. DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
  24. Document doc = documentBuilder.parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
  25. NodeList childNodes = doc.getDocumentElement().getChildNodes();
  26. Node[] nodes = new Node[childNodes.getLength()];
  27. for (int index = 0; index < childNodes.getLength(); index++) {
  28. nodes[index] = childNodes.item(index);
  29. }
  30. System.out.println(nodes[1].getTextContent());
  31. }
  32. }
Success #stdin #stdout 0.1s 30300KB
stdin
Standard input is empty
stdout
foobar