On Tue, 24 Oct 2006 14:43:48 +0100, Bill Dueber <[EMAIL PROTECTED]> wrote:
> I've looked through the docs, the tests, and the archives of this > list, but I still can't figure out how to pull out a namespaced node > using xpath. > > I've got a document that looks much like this -- a metadata wrapper > around a MARC-XML-namespaced internal record. > > <?xml version = "1.0" encoding = "UTF-8"?> > <source_full_info> > <source_internal_number>000000668</source_internal_number> > <record xmlns="http://www.loc.gov/MARC21/slim" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://www.loc.gov/MARC21/slim > http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"> > <controlfield tag="001">UMI00003</controlfield> > <datafield tag="245" ind1="1" ind2=" "> > <subfield code="a">International Political Science > Abstracts</subfield> > </datafield> > </record> > </source_full_info> > > ...and can't for the life of me figure out how to get at the <record>. > The docs seem to claim that if I don't give a namespace it'll match > any namespace, but this seems to not be the case. > > I know this is a "devel" list, but any help would be appreciated. > I believe the problem here stems from the default namespace declaration you have on the record element - Xpath doesn't play too well with that. There might be a better way (it gets a bit vague and implementation-dependent here, I'll have to look into how libxml2 handles this) but one workaround is: doc.find('//*[local-name()="record"]') (Select everything, then subselect stuff whose local (i.e. non-prefixed) name matches what you're after). -- Ross Bamford - [EMAIL PROTECTED] _______________________________________________ libxml-devel mailing list libxml-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/libxml-devel