XalanNode getNodeValue always returns NULL

R

Rene van Hoek

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.
 
M

Martin Honnen

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-Level-2-Core-20001113/core.html#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.
 
R

Rene van Hoek

Martin Honnen said:
Rene van Hoek wrote:



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-Level-2-Core-20001113/core.html#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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top