java - How to retrieve prefixed child elements using JDom -
I have the following XML snippet, from which I am trying to use the first element ZOOM, but I'm nullpointer I'm getting the exception. If someone knows, help me.
& lt; Db1: Customer xmlns: db1 = "http://www.project1.com/db1" & gt; & Lt; DB1: CUSTOMERID & gt; 22 & lt; / DB1: CUSTOMERID & gt; & Lt; DB1: CUSTOMERNAME & gt; PRASAD44 & lt; / DB1: CUSTOMERNAME & gt; & Lt; DB1: Address & gt; Chennai & lt; / DB1: Address & gt; & Lt; DB1: Email & gt; Pkk@gmail.com< / DB1: Email & gt; & Lt; DB1: LASTUPDATE & gt; 2014-08-01T00: 00: 00 + 05: 30 & lt; / DB1: LASTUPDATE & gt; & Lt; DB1: nameDetail & gt; BSM_RESTeter & lt; / DB1: nameDetail & gt; & Lt; DB1: phoneBiz & gt; 99 16347 9 42 & lt; / DB1: phoneBiz & gt; & Lt; DB1: phoneHome & gt; 99 16347 9 42 & lt; / DB1: phoneHome & gt; & Lt; DB1: phoneMobile & gt; 944,990,031 & lt; / DB1: phoneMobile & gt; & Lt; DB1: Ratings & gt; 22 & lt; / DB1: Ratings & gt; & Lt; / DB1: Customer & gt;
What I'm doing here,
SAXbuilder builder = new SAXbuilder (); File xmlFile = new file ("CommonFiles / file.xml"); Document document = (document) manufacturer. Build (xmlFile); Element routerode = doc.getRootElement (); Element Client Id = Routodeodgett ("Make sure: Customer ID"); System.out.println ("Subscriber ======" + Subscriptions);
The print statement displays blank.
XML namespace, you can use the appropriate namespace
for your code Have to use. In this case, you have:
& lt; Db1: Customer xmlns: db1 = "http://www.project1.com/db1" & gt;
Here the name space is http://www.project1.com/db1
and the prefix is db1
.
/ DB1 ");
Now, when you retrieve the content in your document, use it:
< Code> Element customerid = RootNode.getChild ("customerId", db1);
Note that you obtain the content using the namespace object, the prefix for the element is not (" Customer ID "has no" db1: "prefix
Comments
Post a Comment