![]() |
XalanNode getNodeValue always returns NULL
Hi,
I am using Xalan 1.8.0 and Xerces 2.6.0 in C++. I have an XML document which I first transform into an other XML document using an XSL styelsheet. Then I want to parse with XPathEvaluator the new XML document. I succeed in transforming, also in parsing with the XPathEvaluator. But I can not get any nodeValue, getNodeValue() returns NULL. A snapshot of the code is below: for (int cnt = 0; cnt < length; cnt++) { DOMNode* sheet = sheets->item(cnt); XercesDocumentWrapper theXalanDoc(theDOM, true, true, true); XercesWrapperNavigator theNavigator(&theXalanDoc); XalanNode* theSheet = theXalanDoc.mapNode(sheet); XalanSourceTreeDOMSupport theDOMSupport; XalanDocumentPrefixResolver thePrefixResolver(&theXalanDoc); XPathEvaluator theEvaluator; // OK, let's find the context node... XalanNode* const theSeqNode =theEvaluator.selectSingleNode(theDOMSupport, theSheet, L"./seq", thePrefixResolver); XalanNode::NodeType type = theSeqNode->getNodeType(); //getNodeValue Always returns NULL ???? XalanDOMString sheet_seq = theSeqNode->getNodeValue(); } I am new in using Xerces and Xalan, so this code may seem clumsy to you. The getNodeType returns an value I excpet, also the method getNodeName(), getNodeValue() always returns NULL. The XML source has an value. The complete code is below: DOMDocument * theDOM = DOMImplementation::getImplementation()->createDocument(); XMLErrorHandling::XMLError xml_error(_sloc); FormatterToXercesDOM theFormatter(theDOM, NULL); try { XalanTransformer theXalanTransformer; theXalanTransformer.setErrorHandler(&xml_error); theXalanTransformer.transform("xml_file.xml", L"questionaire_retrieve_sheets.xsl", theFormatter); } catch (...) { theDOM->release(); theDOM = NULL; return 0; } int length = 0; DOMNodeList* sheets = NULL; sheets = theDOM->getElementsByTagName(std::wstring(L"sheet").c_str ()); if (NULL == sheets) return 0; length = sheets->getLength(); for (int cnt = 0; cnt < length; cnt++) { DOMNode* sheet = sheets->item(cnt); XercesDocumentWrapper theXalanDoc(theDOM, true, true, true); XercesWrapperNavigator theNavigator(&theXalanDoc); XalanNode* theSheet = theXalanDoc.mapNode(sheet); XalanSourceTreeDOMSupport theDOMSupport; XalanDocumentPrefixResolver thePrefixResolver(&theXalanDoc); XPathEvaluator theEvaluator; // OK, let's find the context node... XalanNode* const theSeqNode = theEvaluator.selectSingleNode(theDOMSupport, theSheet, L"./seq", thePrefixResolver); XalanNode::NodeType type = theSeqNode->getNodeType(); XalanDOMString sheet_seq = theSeqNode->getNodeValue(); } Thanks you in advance. |
Re: XalanNode getNodeValue always returns NULL
Rene van Hoek wrote: > I am using Xalan 1.8.0 and Xerces 2.6.0 in C++. > > I have an XML document which I first transform into an other XML > document using an XSL styelsheet. Then I want to parse with > XPathEvaluator the new XML document. > > I succeed in transforming, also in parsing with the XPathEvaluator. > But I can not get any nodeValue, getNodeValue() returns NULL. > > A snapshot of the code is below: > > for (int cnt = 0; cnt < length; cnt++) { > DOMNode* sheet = sheets->item(cnt); > > XercesDocumentWrapper theXalanDoc(theDOM, true, true, true); > XercesWrapperNavigator theNavigator(&theXalanDoc); > XalanNode* theSheet = theXalanDoc.mapNode(sheet); > > XalanSourceTreeDOMSupport theDOMSupport; > XalanDocumentPrefixResolver thePrefixResolver(&theXalanDoc); > XPathEvaluator theEvaluator; > > // OK, let's find the context node... > XalanNode* const theSeqNode > =theEvaluator.selectSingleNode(theDOMSupport, theSheet, L"./seq", > thePrefixResolver); > XalanNode::NodeType type = theSeqNode->getNodeType(); > //getNodeValue Always returns NULL ???? > XalanDOMString sheet_seq = theSeqNode->getNodeValue(); > } > > I am new in using Xerces and Xalan, so this code may seem clumsy to > you. The getNodeType returns an value I excpet, also the method > getNodeName(), getNodeValue() always returns NULL. The XML source has > an value. What kind of node is that, an element node? For element nodes the nodeValue is defined to be null, it is not (as many people expect) the content of the element. Here is the W3C DOM definition of Node and nodeValue: http://www.w3.org/TR/2000/REC-DOM-Le...#ID-1950641247 You might want ./seq/text() as the XPath expression you evaluate, that returns (with selectSingleNode) as single text node and for text nodes the nodeValue is the text content. This is all based on my experience with other DOM and XPath implementations I know, I don't use Xalan/Xerces C myself. -- Martin Honnen http://JavaScript.FAQTs.com/ |
Re: XalanNode getNodeValue always returns NULL
Martin Honnen <mahotrash@yahoo.de> wrote in message news:<419cf383$0$6968$9b4e6d93@newsread4.arcor-online.net>...
> Rene van Hoek wrote: > > > > I am using Xalan 1.8.0 and Xerces 2.6.0 in C++. > > > > I have an XML document which I first transform into an other XML > > document using an XSL styelsheet. Then I want to parse with > > XPathEvaluator the new XML document. > > > > I succeed in transforming, also in parsing with the XPathEvaluator. > > But I can not get any nodeValue, getNodeValue() returns NULL. > > > > What kind of node is that, an element node? For element nodes the > nodeValue is defined to be null, it is not (as many people expect) the > content of the element. > Here is the W3C DOM definition of Node and nodeValue: > http://www.w3.org/TR/2000/REC-DOM-Le...#ID-1950641247 > > You might want > ./seq/text() > as the XPath expression you evaluate, that returns (with > selectSingleNode) as single text node and for text nodes the nodeValue > is the text content. > > This is all based on my experience with other DOM and XPath > implementations I know, I don't use Xalan/Xerces C myself. Hi, Thanks for your reply. The returned node type is an element node. Indeed according to the specification, the nodevalue is defined to be NULL. When I do ./seq/text() I get an text node, which has an value. Thanks. |
| All times are GMT. The time now is 11:39 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.