import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
// The main method must be in a class named "Main".
class Main {
public static void main(String[] args) {
String xmlStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
"<books>" +
" <book>" +
" <author>" +
" <firstName>Bert</firstName>" +
" <id>1</id>" +
" <lastName>Bates</lastName>" +
" </author>" +
" <isbn>ISBN-45565-45</isbn>" +
" <title>Head First Java</title>" +
" </book>" +
"</books>";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
try
{
builder = factory.newDocumentBuilder();
Document doc = builder.parse( new InputSource( new StringReader( xmlStr ) ) );
var node = doc
.getElementsByTagName("isbn")
.item(0)
.getTextContent();
System.out.println(node);
} catch (Exception e) {
System.out.println(e);
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: