You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by Paul Lalonde <pl...@neoptica.com> on 2006/09/08 23:06:58 UTC

XalanSimplePrefixResolver and XPath

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi.  I'm tring to use Xalan's XPath support to run queries on some  
Collada documents I have.  I've run into the issue that the documents  
all declare themselves in an anonymous namespace:
	<?xml version="1.0" encoding="utf-8"?>
	<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema"  
version="1.4.0">
		<asset>
		...
		</asset>
	</COLLADA>
	
So I want my XPath expressions to refer through that namespace.  I  
thought I'd try using the XalanSimplePrefixResolver doing something  
like this:
         XalanSimplePrefixResolver thePrefixResolver(
                                   XalanDOMString("c"),
                                   XalanDOMString("http:// 
www.collada.org/2005/11/COLLADASchema"),
                                   XalanDOMString("http:// 
www.collada.org/2005/11/COLLADASchema")
                                   );

         XPathEvaluator	theEvaluator;

         // OK, let's find the COLLADA root node...
         XalanNode*	theContextNode = theEvaluator.selectSingleNode(
                        theDOMSupport,
                        theDocument,
                        XalanDOMString("/c:COLLADA"),.c_str(),
                        thePrefixResolver);


But all I get are exceptions:
	XSL exception: The prefix 'c' is not declared.
	
Now, I'm clearly guessing on the declaration of the XalanSimplePrefix  
resolver, as I don't know the difference between the URI and the  
NamespaceURI parameters to the constructor.

What am I doing wrong?  If I ditch the xmlns declaration out of my  
xml file (and ignore the resolver...) all is fine.

Thanks,

Paul

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)

iD8DBQFFAdtyr7+oA6AsvAkRAgWhAJ0VNdpBsv073Yp87rGGv73WBn8R7wCfSi0g
i59+/bwfr4fKA/zX4SHMvME=
=DgnI
-----END PGP SIGNATURE-----

Re: XalanSimplePrefixResolver and XPath

Posted by David Bertoni <db...@apache.org>.
Paul Lalonde wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Success!  Thank you!
> 
> I'm guessing now that holding the handle is a general rule for the API?  
> Is there an easy way to tell for any call if a reference gets retained?
> 

Unfortunately, this isn't consistently documented.  In general, references 
are held to avoid unnecessary copying, but the best way to figure this out 
is to take a quick look at the header file.

Dave

Re: XalanSimplePrefixResolver and XPath

Posted by Paul Lalonde <pl...@neoptica.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Success!  Thank you!

I'm guessing now that holding the handle is a general rule for the  
API?  Is there an easy way to tell for any call if a reference gets  
retained?

Thanks,
     Paul

On 8-Sep-06, at 4:29 PM, David Bertoni wrote:

> Paul Lalonde wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>> Hi.  I'm tring to use Xalan's XPath support to run queries on some  
>> Collada documents I have.  I've run into the issue that the  
>> documents all declare themselves in an anonymous namespace:
>>     <?xml version="1.0" encoding="utf-8"?>
>>     <COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema"  
>> version="1.4.0">
>>         <asset>
>>         ...
>>         </asset>
>>     </COLLADA>
>>     So I want my XPath expressions to refer through that  
>> namespace.  I thought I'd try using the XalanSimplePrefixResolver  
>> doing something like this:
>>         XalanSimplePrefixResolver thePrefixResolver(
>>                                   XalanDOMString("c"),
>>                                   XalanDOMString("http:// 
>> www.collada.org/2005/11/COLLADASchema"),
>>                                   XalanDOMString("http:// 
>> www.collada.org/2005/11/COLLADASchema")
>>                                   );
>
> XalanSimplePrefixResolver holds references to existing  
> XalanDOMString instances, and you are passing in temporaries that  
> are destroyed after the constructor is called.  As a result, the  
> instance contains references to three XalanDOMString instances that  
> have already been destroyed.  When the XPath compiler attempts to  
> use the PrefixResolver, it contains garbage data.
>
> Declare the XalanDOMString instances on the stack, not as  
> temporaries, and your code will work.
>
> Dave
>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)

iD8DBQFFAgDCr7+oA6AsvAkRAupnAJ4sarK02tW85Gjxy/r4PNcP9Yg6xACgvDV6
Yup3Nn9N2ud7DbEZoF+sCGE=
=zUQk
-----END PGP SIGNATURE-----

Re: XalanSimplePrefixResolver and XPath

Posted by David Bertoni <db...@apache.org>.
Paul Lalonde wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi.  I'm tring to use Xalan's XPath support to run queries on some 
> Collada documents I have.  I've run into the issue that the documents 
> all declare themselves in an anonymous namespace:
>     <?xml version="1.0" encoding="utf-8"?>
>     <COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" 
> version="1.4.0">
>         <asset>
>         ...
>         </asset>
>     </COLLADA>
>     
> So I want my XPath expressions to refer through that namespace.  I 
> thought I'd try using the XalanSimplePrefixResolver doing something like 
> this:
>         XalanSimplePrefixResolver thePrefixResolver(
>                                   XalanDOMString("c"),
>                                   
> XalanDOMString("http://www.collada.org/2005/11/COLLADASchema"),
>                                   
> XalanDOMString("http://www.collada.org/2005/11/COLLADASchema")
>                                   );
> 

XalanSimplePrefixResolver holds references to existing XalanDOMString 
instances, and you are passing in temporaries that are destroyed after the 
constructor is called.  As a result, the instance contains references to 
three XalanDOMString instances that have already been destroyed.  When the 
XPath compiler attempts to use the PrefixResolver, it contains garbage data.

Declare the XalanDOMString instances on the stack, not as temporaries, and 
your code will work.

Dave