xml - xmllint failing to properly query with xpath -
i'm trying query xml file generated adium. xmlwf says it's formed. using xmllint's debug option following:
$ xmllint --debug doc.xml document version=1.0 encoding=utf-8 url=doc.xml standalone=true element chat default namespace href=http://purl.org/net/ulf/ns/0.4-02 attribute account text content=foo@bar.com attribute service text compact content=msn text compact content= element event attribute type
everything seems parse fine. however, when try query simplest things, don't anything:
$ xmllint --xpath '/chat' doc.xml xpath set empty
what's happening? running exact same query using xpath returns correct results (however no newline between results). doing wrong or xmllint not working properly?
here's shorter, anonymized version of xml shows same behavior:
<?xml version="1.0" encoding="utf-8" ?> <chat xmlns="http://purl.org/net/ulf/ns/0.4-02" account="foo@bar.com" service="msn"> <event type="windowopened" sender="foo@bar.com" time="2011-11-22t00:34:43-03:00"></event> <message sender="foo@bar.com" time="2011-11-22t00:34:43-03:00" alias="foo"><div><span style="color: #000000; font-family: helvetica; font-size: 12pt;">hi</span></div></message> </chat>
i don't use xmllint, think reason xpath isn't working because doc.xml file using default namespace (http://purl.org/net/ulf/ns/0.4-02
).
from can see, have 2 options.
a. use xmllint in shell mode , declare namespace prefix. can use prefix in xpath.
xmllint --shell doc.xml / > setns x=http://purl.org/net/ulf/ns/0.4-02 / > xpath /x:chat
b. use local-name()
match element names.
xmllint --xpath /*[local-name()='chat']
you may want use namespace-uri()='http://purl.org/net/ulf/ns/0.4-02'
along local-name()
sure return intending return.
Comments
Post a Comment