1

I have the below xml and I am trying to retrieve the value of id under BoostBuryDimensionValue tag using the java code but returns nothing. Can some one help me on this. Thanks in advance.

Input XML

 <?xml version="1.0" encoding="UTF-8"?>
<ContentItem type="OrganicZoneContent" xmlns="http://endeca.com/schema/content/2008" >
  <TemplateId>OrganicResults</TemplateId>
  <Name>OrganicResults</Name>
  <Property name="navigation_records">
    <BoostBury rollupKey="grp_id" recspecField="grp_id" xmlns="http://endeca.com/schema/content/xtags/2010">

      <BoostBuryRecords>
        <BoostBuryRecord recordType="CRITERIA" boostBuryType="BOOST">
          <BoostBurySearch terms="null" key="null"/>
          <BoostBuryDimensionValues>
            <BoostBuryDimensionValue id="4294965238" name="career" dimensionName="Occasion"/>
          </BoostBuryDimensionValues>
        </BoostBuryRecord>

      </BoostBuryRecords>
     </BoostBury>
  </Property>
</ContentItem>

and the java code i am using is

public static void main(String[] args) throws Exception { 
    InputStream xml = new FileInputStream("tempinput.xml");
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder(); 
    Document doc = db.parse(xml); 
    XPath xpath = XPathFactory.newInstance().newXPath(); 
    XPathExpression expr = xpath.compile("ContentItem/Property[@name='navigation_records']/BoostBury/BoostBuryRecords/BoostBuryRecord/BoostBuryDimensionValues/BoostBuryDimensionValue/@id");
    Object result = expr.evaluate(doc, XPathConstants.STRING); 
    System.out.println("BoostBuryDimensionValue id = " + result);

} 
newbie25
  • 13
  • 3
  • 1
    You need to register the namespace have a look at this: http://stackoverflow.com/questions/6390339/how-to-query-xml-using-namespaces-in-java-with-xpath – stringy05 Mar 03 '15 at 00:28

0 Answers0