468,268 Members | 1,555 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,268 developers. It's quick & easy.

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.
Jul 20 '05 #1
2 6770


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/
Jul 20 '05 #2
Martin Honnen <ma*******@yahoo.de> wrote in message news:<41**********************@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.
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Waseem | last post: by
ADezii
3 posts views Thread by ADezii | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.