Bugs item #7938, was opened at 2007-01-17 09:52 You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=1971&aid=7938&group_id=494
Category: None Group: None >Status: Closed Resolution: None Priority: 3 Submitted By: Angel Pizarro (delagoya) Assigned to: Nobody (None) Summary: XML schema namespace declarations make XPATH return nil Initial Comment: XML schema namespace decl cause XPATH expressions to return nil. Example below. For some schema foo: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="foo"> <xs:complexType> <xs:sequence minOccurs="0" maxOccurs="1"> <xs:element name="bar" minOccurs="1" maxOccurs="unbounded"> <xs:complexType ><xs:simpleContent > <xs:extension base="xs:int"></xs:extension></xs:simpleContent></xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> (basically elem:foo => elem:bar => content:int ) And this script: #require 'rubygems' # uncomment if libmlx-ruby installed via gems require 'xml/libxml' d = XML::Document.file ARGV[0] r = d.find(ARGV[1]).first puts "#{r.class} ::=> #{r}" r.each { |e| puts "\t#{e.name} = #{e.content}" if e.element? } This XML file does not work: <?xml version="1.0" encoding="UTF-8"?> <foo xmlns="file:/Volumes/DATA/Src/quanto/rampy/test/test.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="file:/Volumes/DATA/Src/quanto/rampy/test/test.xsd"> <bar>2147483647</bar> <bar>2147483647</bar> <bar>2147483647</bar> </foo> But this one does: <?xml version="1.0" encoding="UTF-8"?> <foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="file:/Volumes/DATA/Src/quanto/rampy/test/test.xsd"> <bar>2147483647</bar> <bar>2147483647</bar> <bar>2147483647</bar> </foo> -angel ---------------------------------------------------------------------- >Comment By: Angel Pizarro (delagoya) Date: 2008-10-01 08:29 Message: yep, thanks for the reply! ---------------------------------------------------------------------- Comment By: Benjamin Woosley (empact) Date: 2008-10-01 06:01 Message: This isn't a bug. The default namespace attribute does not have a name, but is a namespace so it's required for the find. So in the case of the xml which "does not work," you'll need to name the default namespace, e.g.: #find('foo:bar', 'foo:file:/Volumes/DATA/Src/quanto/rampy/test/test.xsd'). Where 'foo' is whatever name you decide to give the default namespace in this call. See http://libxml.rubyforge.org/rdoc/classes/LibXML/XML/XPath/InvalidPath.html # Since the getManufacturerNamesResponse element uses a default # namespace we first have to give it a prefix and register # it with the xpath engine. doc.find('//ns:getManufacturerNamesResponse', 'ns:http://services.somewhere.com') ---------------------------------------------------------------------- You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=1971&aid=7938&group_id=494 _______________________________________________ libxml-devel mailing list libxml-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/libxml-devel