java - Is there a single XPath expression I can use to navigate XML in a CDATA section? -


i'm trying figure out how use xpath exceptionid , instrumentid values out of xml snippet in following xml document (yes having xml in cdata little odd, that's 3rd party service)

<?xml version="1.0"?>   <exception>     <info>       <![cdata[         <info>           <exceptionid>1</exceptionid>           <instrumentid>1</instrumentid>         </info>       ]]>     </info> </exception> 

is possible values in 1 xpath statement?

i'm using javax.xml.xpath.xpath inside java (jdk 1.5 xalan 2.7.1 , xerces 2.9.1), e.g.

xpath xpath = xpathfactory.newinstance().newxpath();  long exceptionid  = new long(((double)xpath.evaluate(this.exceptionidxpath,                                 document, xpathconstants.number)).longvalue()); 

it's this.exceptionidxpath variable i'm not sure how set, know example that:

/exception/info/text()/info/exceptionid won't work (text() returns data inside cdata no 'knowledge' xml)

yes, can it. inside cdata section string , won't part of dom. therefore, have use xpath's string manipulation functions.

in xpath can use substring-before , substring-after. may work:

substring-before(substring-after(/exception/info,"<exceptionid>"), "</exceptionid>") 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -