0% found this document useful (0 votes)
24 views1 page

Quick Code

This document shows how to parse an XML document from a URL using Java. It imports necessary classes, creates a DocumentBuilderFactory and DocumentBuilder to parse the XML into a Document object. It then uses XPath to evaluate an XPath query on the Document and iterate through matching nodes, accessing attribute values.

Uploaded by

ripudsudan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views1 page

Quick Code

This document shows how to parse an XML document from a URL using Java. It imports necessary classes, creates a DocumentBuilderFactory and DocumentBuilder to parse the XML into a Document object. It then uses XPath to evaluate an XPath query on the Document and iterate through matching nodes, accessing attribute values.

Uploaded by

ripudsudan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Parsing xml doc

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
DocumentBuilderFactory factory = null;
DocumentBuilder builder;
Document doc = null;
String query = "";
factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
builder = this.factory.newDocumentBuilder();
doc = this.builder.parse(http_url);

XPathFactory xFactory = XPathFactory.newInstance();


XPath xpath = xFactory.newXPath();
this.expr = xpath.compile(query);
Object result = this.expr.evaluate(this.doc, XPathConstants.NODESET);
NodeList nodes = (NodeList)result;
for (int i = 0; i < nodes.getLength(); )
{
Attr houseAttr = (Attr)nodes.item(i);
}

You might also like