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 "ovanes@t-online.de" <ov...@t-online.de> on 2005/11/17 10:46:33 UTC
Re: Applying xPath to Xerces DOMDocument fails
Sorry previous email was formatted as HTML and might be unreadable. Here
it is again in plain text format....
--
Ovanes Markarian
-----Original Message-----
Date: Thu, 17 Nov 2005 10:41:12 +0100
Subject: Applying xPath to Xerces DOMDocument fails
From: "ovanes@t-online.de"
To: "Mailing List, Xalan-C"
Hello,
I am relatively new to Xalan and somehow it drives me mad. I need to
apply an xPath to the pre-parsed XML document. The document is a
Xerces DOMDocument instance.
I read some postings on how to do that, but none of them worked. I
will try to summerize my efforts below:
I saw a post from Joerg Seidler:
http://marc.theaimsgroup.com/?l=xalan-c-users&m=108385669500218&w=2
and tried to do it in similar way, but with no luck.
My system configuration is:
Xerces-C 2.7.0
Xalan-C 1.10
May be I forgot some initialization or anything else. Below are my
explanations:
1. Assume that Xerces-C and XPathEvaluator initializations succeeded.
And I have successfully parsed an XML document and have a DOMDocument
instance pointer to which I need xPath to be applied. xPath
expression was successfully tested for this document with XMLSpy and
Oxygen XML Editors (internally uses Xerces-J and Xalan-J). And the
selection always delivered the desired node. I extensively use
namespaces in my document and have my own namespace defined as
default namespace. I know that xPath 1.0 does not support default
namespaces that's why I also write a prefiexed xPath to the desired
element.
My code looks as follows:
//xtcxsl, xtcxml are defined as follows:
/*
#ifdef XERCES_CPP_NAMESPACE
namespace xtcxml=XERCES_CPP_NAMESPACE;
#else
#define xtcxml
#endif
#ifdef XALAN_CPP_NAMESPACE
namespace xtcxsl=XALAN_CPP_NAMESPACE;
#else
#define xtcxsl
#endif
*/
//assume that xPath is defined upon as XMLCh* or char*
xtcxsl::XMLSupportInit xmlSupportInit;
xtcxsl::XercesDOMSupport dom_support;
xtcxsl::XercesParserLiaison parser_liaison(dom_support);
parser_liaison.setBuildWrapperNodes(true);
parser_liaison.setBuildMaps(true);
xtcxsl::XercesDOMWrapperParsedSource xSource(pDoc, parser_liaison,
dom_support); //xtcxml::DOMDocument* pDoc is defined upon.
xtcxsl::XalanDocument& xeDoc = *xSource.getDocument();
xtcxsl::XalanElement* ns_node = xeDoc.getDocumentElement();
xtcxsl::XPathEvaluator evaluator;
xtcxsl::NodeRefList result;
//resulting list has no elements
evaluator.selectNodeList(result, dom_support, ns_node, xPath,
ns_node);
//node pointer is NULL
xtcxsl::XalanNode* node=evaluator.selectSingleNode(dom_support,
ns_node, xPath, ns_node);
Using command line sample SimpleXPathAPI with the sampe xml document
and xPath returns a valid node.
Can someone point me to what is wrong?
Many thanks!
--
Ovanes Markarian