Re: [xml] xmlParseFile and xmlns
- From: Michael Ludwig <mlu as-guides com>
- To: xml gnome org
- Subject: Re: [xml] xmlParseFile and xmlns
- Date: Wed, 22 Apr 2009 11:24:51 +0200
Juhani Connolly schrieb:
When using xmllib to parse an rss feed that includes an unquallified
xml namespace the document will include nothing.
Hi Juhani,
I guess you mean what's called the default namespace (no prefix).
Are we meant to be doing something special before calling xmlParseFile
(or another similar function)?
I'd say so, if we want to work with namespaces.
<feed xmlns='http://www.w3.org/2005/Atom'
xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' >
Feeding any similar feed through a barebones test program with an
xmlParseFile and xpath operation for something like //item
there are no hits.
The expression //item looks for element nodes named "item" *in no
namespace*. Your feed has "item" nodes in the Atom namespace.
Upon deleting [xmlns='http://www.w3.org/2005/Atom'] it works fine, all
the items are picked up.
Yes, because now the default namespace (no prefix) is mapped to the
empty namespace, not to the Atom namespace.
If anyone knows what causes this issue and how to get around it
correctly I would really appreciate any solution/explanation that
could be given.
I don't know the C API, but you have to register namespaces with
prefixes in the XPath context and then search for //atom:item. Maybe
this pointer to the API doc will lead you on the right track:
http://xmlsoft.org/html/libxml-xpath.html#xmlXPathContext
Note the reference to "xmlNsPtr * namespaces : Array of namespaces".
I think this is what you need to fill, but not knowing the C API, I'm
not 100 % sure.
Michael Ludwig
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]