Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to retrieve blank values from XML node
    primarykey
    data
    text
    <p>I have an XML as below</p> <pre><code>&lt;Element&gt; &lt;Name&gt;srmgmtaddress&lt;/Name&gt; &lt;Value&gt;10.133.14.19&lt;/Value&gt; &lt;/Element&gt; &lt;Element&gt; &lt;Name&gt;crlbif0&lt;/Name&gt; &lt;Value/&gt; &lt;/Element&gt; &lt;Element&gt; &lt;Name&gt;srseid.srtype&lt;/Name&gt; &lt;Value&gt;Cisco c7206VXR&lt;/Value&gt; &lt;/Element&gt; &lt;Element&gt; &lt;Name&gt;craddressinterim&lt;/Name&gt; &lt;Value/&gt; &lt;/Element&gt; &lt;Element&gt; &lt;Name&gt;crvrfinterim&lt;/Name&gt; &lt;Value/&gt; &lt;/Element&gt; </code></pre> <p>I want to retrieve the Element Values and I'm using the XPath expression <code>//ResponseItem/Object/Element/Value/text()</code> where ResponseItem and Object are two upper level nodes.</p> <p>This works fine with the code below:</p> <pre><code>ArrayList&lt;String&gt; elementsToFetch = new ArrayList&lt;String&gt;(Arrays.asList("//ResponseItem/Object/Element/Name/text()","//ResponseItem/Object/Element/Value/text()")); for (String n : elementsToFetch) { XPathFactory xPathfactory1 = XPathFactory.newInstance(); XPath xpath1 = xPathfactory1.newXPath(); XPathExpression expr1 = xpath1.compile(n); NodeList nl = (NodeList) expr1.evaluate(doc1, XPathConstants.NODESET); for (int i=0;i&lt;nl.getLength();i++) { String nodeval = nl.item(i).getNodeValue(); //...SOME CODE HERE } } </code></pre> <p>But I also want to retrieve the blank XML node values in "crlbif0", "craddressinterim" etc as NULL or "".</p> <p>Right now I'm getting the list as below where blank nodes are not getting processed</p> <pre><code>[CRNdNode_RO:1024, chn-pe2-rt02, 10.133.14.19, Cisco c7206VXR, CRNdNode_RO:1037, chn-pe4-rt04, 10.133.14.6, Cisco c7609 ...] </code></pre> <p>I want the list as </p> <pre><code>[CRNdNode_RO:1024, chn-pe2-rt02, 10.133.14.19, "", Cisco c7206VXR, "", "", CRNdNode_RO:1037, chn-pe4-rt04, 10.133.14.6, "", Cisco c7609, "", "",....] </code></pre> <p>Any help in this regard will be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload