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 Alex Fridman <al...@automatedfinancial.com> on 2001/03/23 23:29:33 UTC

Dom parser issue

Hi,

I have a technical question.

I am using the DOMParser to parse the xml file.  It parses the file and
builds the DOM_Document just fine. It also works when I ask for any node in
the tree, but for some reason it fails when I call getNodeValue() function
to get the value of the node, although the node definitely has a value in my
file.

This is the peace of code that's failing
	DOM_Document document=parser->getDocument();
	DOM_NodeList iqList=document.getElementsByTagName("iq");
	if(iqList.getLength()){
		DOM_Node iqTag=iqList.item(0);
		DOM_NamedNodeMap iqAtt=iqTag.getAttributes();
		DOM_Node type=iqAtt.getNamedItem("type");
		cout << "Type " + String(type.getNodeValue().transcode()) <<
endl;
		if(String(type.getNodeValue().transcode()) == "error"){
			DOM_NodeList
errorList=document.getElementsByTagName("error");
			if(errorList.getLength()){
				DOM_Node errorTag=errorList.item(0);
				DOM_NamedNodeMap
errorAtt=errorTag.getAttributes();
				DOM_Node code=errorAtt.getNamedItem("code");
				cout << errorTag.getNodename().transcode()
<< endl; //this works
				cout << errorTag.getNodeValue().transcode()
<< endl; //this does not
				cout << code.getNodeValue().transcode() <<
endl;
				throw Exception("Code " +
String(code.getNodeValue().transcode()) + " Message "+ String
(errorTag.getNodeValue().transcode()));
			}else{
				throw Exception("Invalid register responce
from the server");	
			}
		}
	}else{
		throw Exception("Invalid register responce from the
server");	
	}

Thanks,
Alex Fridman
Automated Financial Systems
(212)771-1923 

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


Re: Dom parser issue

Posted by Gareth Reakes <ga...@decisionsoft.com>.
Hello,

Gareth Reakes, Lead Software Engineer  
DecisionSoft Ltd.            http://www.decisionsoft.com
Office: +44 (0) 1865 203192


On Fri, 23 Mar 2001, Alex Fridman wrote:

> Hi,
> 
> I have a technical question.
> 
> I am using the DOMParser to parse the xml file.  It parses the file and
> builds the DOM_Document just fine. It also works when I ask for any node in
> the tree, but for some reason it fails when I call getNodeValue() function
> to get the value of the node, although the node definitely has a value in my
> file.
> 
> This is the peace of code that's failing
> 	DOM_Document document=parser->getDocument();
> 	DOM_NodeList iqList=document.getElementsByTagName("iq");
> 	if(iqList.getLength()){
> 		DOM_Node iqTag=iqList.item(0);
> 		DOM_NamedNodeMap iqAtt=iqTag.getAttributes();
> 		DOM_Node type=iqAtt.getNamedItem("type");
> 		cout << "Type " + String(type.getNodeValue().transcode()) <<
> endl;
> 		if(String(type.getNodeValue().transcode()) == "error"){
> 			DOM_NodeList
> errorList=document.getElementsByTagName("error");
> 			if(errorList.getLength()){
> 				DOM_Node errorTag=errorList.item(0);
> 				DOM_NamedNodeMap
> errorAtt=errorTag.getAttributes();
> 				DOM_Node code=errorAtt.getNamedItem("code");
> 				cout << errorTag.getNodename().transcode()
> << endl; //this works
> 				cout << errorTag.getNodeValue().transcode()
> << endl; //this does not

This would not work as DOM_Element Nodes do not have a node value. If you
are trying to print out the contents then look at the DOMSerialize
example.

hope this helps,

Gareth



> 				cout << code.getNodeValue().transcode() <<
> endl;
> 				throw Exception("Code " +
> String(code.getNodeValue().transcode()) + " Message "+ String
> (errorTag.getNodeValue().transcode()));
> 			}else{
> 				throw Exception("Invalid register responce
> from the server");	
> 			}
> 		}
> 	}else{
> 		throw Exception("Invalid register responce from the
> server");	
> 	}
> 
> Thanks,
> Alex Fridman
> Automated Financial Systems
> (212)771-1923 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
> 
> 


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