xml - Java Xpath query failing on compile -


i have following xml document:

<application xmlns="http://www.example.com/schemas/app-config/1.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:schemalocation="http://www.example.com/schemas/app-config/1.0   http://www.example.com/schemas/app-config/1.0/app-config-1.0.xsd">     <info name="dummy application" runningon="dev"/> </application> 

when run following code:

xpathfactory factory = xpathfactory.newinstance(); xpath xpath = factory.newxpath(); xpathexpression expr = xpath.compile("/application/info@name"); 

i xpathexpressionexception on compile method. exception's message "null". looks i'm correctly using xpath locate name attribute, i'm wondering if xmlns , xsi declarations causing problems here? if not i'm totally clueless , have no idea what's causing exception.

one thing - how can compile failing before ever associate xpath instance actual document object?!?

you have syntax error in expression /application/info@name, correct syntax /application/info/@name. note xml sample has default namespace xpath 1.0 expression /application/info/@name not select in sample, xpath 2.0 need make sure associate define default namespace xpath evaluation. xpath 1.0 need define prefix (e.g. df) default namespace in java code , use e.g. /df:application/df:info/@name. not familiar java xpath api else needs concrete code on how set namespaces xpathnamespacecontext or similar.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -