ruby - Why can't I get a result from an XPath with namespace in the root element? -


this question has answer here:

this xml namespace newbie question can't figure out how xpath work following trunctated xml particular root element:

<?xml version="1.0" encoding="utf-8"?> <createorupdateeventsrequest xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://dhamma.org" version="3-0-0">    <languagekey>     <isocode>en</isocode>   </languagekey>   <publish>     <value>true</value>   </publish>   <events>     <event>       <eventkey>         <locationkey>           <subdomain>rasmi</subdomain>         </locationkey>         <eventid>10daypdfstdtag</eventid>       </eventkey>     </event>   </events>    </languagekey> </createorupdateeventsrequest> 

using ruby , nokogiri (with updated libxml2), works fine xpath if delete info in root element, making it:

<createorupdateeventsrequest> 

otherwise nothing works:

$> @doc.xpath("//createorupdateeventsrequest") #=> [] original header, array of nodes modified header $> @doc.xpath("//languagekey") #=> [] original header, array of nodes modified header  $> @doc.xpath("//xmlns:languagekey") #=> undefined namespace prefix original 

how address namespaces xpath?

many help.

the answer seems xml re-declared xmlns when should have declared namespace prefix in xmlns:myns.

from www.w3.org:

the xml specification reserves names beginning letters 'x', 'm', 'l' in combination of upper- , lower-case use w3c. date 3 such names have been given definitions—although these names not in xml namespace, listed here convenience readers , users:


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -