You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Dinker Charak <di...@fnal.gov> on 2002/07/25 20:06:57 UTC

Is newline treated as a node on purpose?

Hello,

Environment
===========
PC/Linux. Xerces C++ 1.7

Desciption
==========
If I have an xml file like this ...

<topnode>
<firstchild>
</firstchild>
<secondchild>
</secondchild>
</topnode>

my program gives this output:

[dinker@odsdin src]$ tryxml < witheol.xml
#text
firstchild
#text
secondchild
#text

But for an xml file like this

<topnode><firstchild></firstchild><secondchild></secondchild></topnode>

my program gives this output:

[dinker@odsdin src]$ tryxml < withouteol.xml
firstchild
secondchild

Is this a bug or expected behaviour?

Test Program
============

// tryxml.cpp
#include <iostream>
#include <string>

#include <util/PlatformUtils.hpp>
#include <dom/DOM.hpp>
#include <framework/MemBufInputSource.hpp>
#include <parsers/DOMParser.hpp>


static std::string DOMString2string(const DOMString& dstr)
{
        char transcodechar[1024];
        strcpy(transcodechar,dstr.transcode());
        return transcodechar;
}

int main(int argC, char* argV[])
{
        std::string msg, ln;
	
        while (getline(cin,ln))
        {
                msg = msg + ln + "\n";
        }
	
	DOMParser *_pDom;
	
       	XMLPlatformUtils::Initialize();
    
    	_pDom = new DOMParser;
	
    	_pDom->setValidationScheme(DOMParser::Val_Never);
    	_pDom->setDoNamespaces(false);
    	_pDom->setDoSchema(false);

	_pDom->reset();
	
	try
	{
	        MemBufInputSource source( (const XMLByte*) (msg.c_str()),
msg.length(), "source", false);
                source.setCopyBufToStream(false);
                _pDom->parse(source);

	        DOM_Document doc =
_pDom->getDocument();                                

	        if (doc.isNull())
	        {
		        throw;
	        }

	        DOM_Node topNode;

	        topNode = doc.getFirstChild();    

	        DOM_NodeList nodeList = topNode.getChildNodes();
	        unsigned int nodeListLen = nodeList.getLength();
	        DOM_Node nodePtr;

	        for(unsigned int idx1=0; idx1 < nodeListLen; idx1++) 
	        {
		        nodePtr = nodeList.item(idx1);
                        cout << DOMString2string(nodePtr.getNodeName())
<< endl;
	        } 
        }        
	catch (...) 
	{
		cerr << "Mangled incoming message: " << DOMString2string(msg.c_str())
<< endl;
	}	

	delete _pDom;
	XMLPlatformUtils::Terminate();
	
	return 0;
}

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org