For accessing all the elements irrespective of namespaces use:
 SelectSingleNode
("*[local-name(.)='ElementName']/*[local-name(.)='SubElement']/text()" ,
CurrentContext ) ;

For accessing all the elements from specific namespaces you can use
something like:
 SelectSingleNode ("*[local-name(.)='ElementName' and
namespace-uri(.)='xyz.org']/*[local-name(.)='SubElement' and
namespace-uri(.)='xyz.org']/text()" ,  CurrentContext ) ;

HTH,
Suresh


-----Original Message-----
From: Michael Hughes [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 04, 2003 5:17 PM
To: xalan-c-users@xml.apache.org
Subject: RE: Namespace support


Thanks David, I tried that and it worked ok.

Next problem :-)

My document looks something like this:-

<documentElement  xmlns="http://www.michael_namespace.com/schema/";
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
 
xsi:schemaLocation="http://www.michael_namespace.com/schema/
michaelSchema.xsd">

   <GreatGrandParent>  
      <GrandParent name="FFA">
         <Parent name="default">
            <Child xsi:type="Child_A_Type" location="xyz" />      
        ...
   </GreatGrandParent>

Now I can query using 'xsi' prefix for the relevant attribute and that
works fine. My next problem is that I can't seem to access the stuff in
the default namespace.

Any help much appreciated.

Thanks in advance.


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: 03 June 2003 18:54
To: xalan-c-users@xml.apache.org
Subject: Re: Namespace support






> I want to configure support for namespaces when querying nodes from a 
> XalanDocument (this isn't strictly correct, but you should get the
> idea):-
>
>
> SelectSingleNode( const std::string & xPathExpression, XalanNode * 
> Context ) {
>     TheEvaluator->selectSingleNode( *TheDOMSupport,
>                                     Context,
>                                     XalanDOMString(
> xPathExpression.c_str() ).c_str() ) ;
>
> }
>
> Problem: This call causes a core dump whenever I request something 
> like
> this:-
>
> SelectSingleNode ( "prefix:ElementName/prefix:SubElement/text()" , 
> CurrentContext ) ;

I suspect you're getting a core dump because an exception is being
thrown which you're not catching.  The documentation for XPathEvaluator
looks like
this:

       * @param domSupport An instance of the corresponding
DOMSupport-derived for the DOM implementation being used.
       * @param contextNode The source tree context node
       * @param xpathString The XPath expression to evaluate
       * @param namespaceNode A node to use for namespace prefix
resolution.

So you can see the last parameter, which you're omitting, can be an
instance of a XalanElement, which the XPathEvaluator instance will use
to resolve prefixes.  If the namespace declaration for "prefix" occurs
on the document element, you can do the following:

     TheEvaluator->selectSingleNode( *TheDOMSupport,
                                     Context,
 
XalanDOMString(xPathExpression.c_str()
).c_str(),

Context->getOwnerDocument()->getDocumentElement() ) ;

Otherwise, you can create your own derivative of PrefixResolver and
return whatever string you want to bind to "prefix."

If you download the lastest CVS code, you'll find a new class called
XalanDocumentPrefixResolver, which searches the entire document for
namespace declarations.  This won't work in the case where "prefix" is
bound to multiple namespace URIs, but it does work for the simpler ones.
If you want to use prefixes which are not defined in the instance
document, you'll need your own derivate of PrefixResolver.

> As a side point, how can the documentation be improved, I find it 
> somewhat lacking in detail ;-)

It can be improved by people volunteering to work on it.  ;-)

Dave

Reply via email to