Quantcast
Channel: SCN : Unanswered Discussions - Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 6719

Using XPath in Java Mapping

$
0
0

Hi Guys,

 

I am using XPath in my Java Mapping and unfortunately not getting out from the node. Please find piece of code below using which I am extracting Value from node.

 

DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();

  DocumentBuilder db=factory.newDocumentBuilder();

  XPathFactory xfactory=XPathFactory.newInstance();

  XPath xpath=xfactory.newXPath();

  String exp=null;

  InputSource is=new InputSource();

  NodeList nl=null;

  Node node=null;

  ByteArrayInputStream bis = new ByteArrayInputStream(xml.getBytes());

  Document doc=db.parse(bis);

 

 

  exp= "/ns0:MT_Source_JM/Record//Employee[2]/text()";

 

  node=(Node)xpath.evaluate(exp,doc,XPathConstants.NODESET);

  System.out.println("XPath Value=["+node.getNodeName()+"]");

 

 

 

 

  }

  catch(Exception e)

  {

  e.printStackTrace();

  }

 

 

My XML is below

 

<ns0:MT_Source_JM xmlns:ns0="http://aa.com/test">

<Record>

<Employee id="1">

<age>29</age>

<name>Pankaj</name>

<gender>male</gender>

<role>Java Developer</role>

</Employee>

<Employee id="2">

<age>35</age>

<name>Lisa</name>

<gender>male</gender>

<role>CEO</role>

</Employee>

</Record>

</ns0:MT_Source_JM>

 

 

 

I need your help in executing this java code through which I can access node value through Xpath or help me with links where I can find help.

 

Regards,

Shankul


Viewing all articles
Browse latest Browse all 6719

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>