XalanNode getNodeValue always returns NULL

Discussion in 'XML' started by Rene van Hoek, Nov 18, 2004.

  1. 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.
    Rene van Hoek, Nov 18, 2004
    #1
    1. Advertising

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

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Nov 18, 2004
    #2
    1. Advertising

  3. Martin Honnen <> wrote in message news:<419cf383$0$6968$-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-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.
    Rene van Hoek, Nov 19, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Fidge
    Replies:
    0
    Views:
    1,105
    Ben Fidge
    Jan 15, 2005
  2. Stefan Cordes
    Replies:
    0
    Views:
    602
    Stefan Cordes
    May 10, 2004
  3. vizlab
    Replies:
    3
    Views:
    4,184
    Michael Bar-Sinai
    Oct 17, 2007
  4. DC
    Replies:
    0
    Views:
    735
  5. Dominik Weinhold
    Replies:
    0
    Views:
    137
    Dominik Weinhold
    Nov 12, 2013
Loading...

Share This Page