You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Ghazanfar <gh...@yahoo.com> on 2006/09/05 08:55:05 UTC

XML DTD Validation C++

Hello Every One,

I have an application that is supposed to read the content from the XML file
and display them on the screen. XML file generated by a Java Application,
this XML corresponds to the Property Object in Java i.e. in java i am using
PropertyFile object to load this XML. When i try to load that XML in my
application using the following code i am unable to get the list of child
nodes from it.

	XMLPlatformUtils::Initialize();

	DTDValidator * dtdValidator = NULL;
	xercesc_2_6::XercesDOMParser *parser = NULL;
	xercesc_2_6::AbstractDOMParser::ValSchemes valScheme =
xercesc_2_6::AbstractDOMParser::Val_Auto;

	dtdValidator = new DTDValidator();
	parser = new XercesDOMParser(dtdValidator);
	parser->setValidationScheme(valScheme);

	CString szPath = m_szFileName;
	parser->parse( T2A( (LPTSTR)szPath.GetBuffer(szPath.GetLength()) ) );
	int nErrorCount = parser->getErrorCount();

	xercesc_2_6::DOMDocument *pDocument = parser->getDocument();
	if(pDocument == NULL)
	{
		delete parser;
		XMLPlatformUtils::Terminate();
		return;
	}
	//Properties
	xercesc_2_6::DOMNode *nodeProperties = pDocument->getFirstChild();
	if(nodeProperties == NULL)
	{
		delete parser;
		XMLPlatformUtils::Terminate();
		return;
	}

	//This should return TRUE but it giving me false.
	bool bChild = nodeProperties->hasChildNodes();

Can any one please tell me where i am going wrong while parsing the
following XML. The XML file is UNICODE format.

<?xml version="1.0" encoding="UTF-16"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>My XML File</comment>
<entry key="KEY2">京 喂</entry>
<entry key="KEY1">京 京 喂</entry>
<entry key="KEY5">京 京 喂</entry>
<entry key="KEY4">京 京</entry>
<entry key="KEY3">京 京 喂</entry>
</properties>

I also have attached the XML file with this message also.
http://www.nabble.com/user-files/235865/Chinese.xml Chinese.xml 

With Regards,
Ghazanfar
-- 
View this message in context: http://www.nabble.com/XML-DTD-Validation-C%2B%2B-tf2219163.html#a6146889
Sent from the Xerces - C - Users forum at Nabble.com.


Re: XML DTD Validation C++

Posted by Tobias <ub...@gmx.net>.
changing the line
xercesc_2_6::DOMNode *nodeProperties = pDocument->getFirstChild();
to
xercesc_2_6::DOMElement *nodeProperties = pDocument->getDocumentElement();
will do the trick, because the first child of the document is the document 
type in your sample xml.

best regards
tobias

----- Original Message ----- 
From: "Ghazanfar" <gh...@yahoo.com>
To: <c-...@xerces.apache.org>
Sent: Tuesday, September 05, 2006 8:55 AM
Subject: XML DTD Validation C++



Hello Every One,

I have an application that is supposed to read the content from the XML file
and display them on the screen. XML file generated by a Java Application,
this XML corresponds to the Property Object in Java i.e. in java i am using
PropertyFile object to load this XML. When i try to load that XML in my
application using the following code i am unable to get the list of child
nodes from it.

XMLPlatformUtils::Initialize();

DTDValidator * dtdValidator = NULL;
xercesc_2_6::XercesDOMParser *parser = NULL;
xercesc_2_6::AbstractDOMParser::ValSchemes valScheme =
xercesc_2_6::AbstractDOMParser::Val_Auto;

dtdValidator = new DTDValidator();
parser = new XercesDOMParser(dtdValidator);
parser->setValidationScheme(valScheme);

CString szPath = m_szFileName;
parser->parse( T2A( (LPTSTR)szPath.GetBuffer(szPath.GetLength()) ) );
int nErrorCount = parser->getErrorCount();

xercesc_2_6::DOMDocument *pDocument = parser->getDocument();
if(pDocument == NULL)
{
delete parser;
XMLPlatformUtils::Terminate();
return;
}
//Properties
xercesc_2_6::DOMNode *nodeProperties = pDocument->getFirstChild();
if(nodeProperties == NULL)
{
delete parser;
XMLPlatformUtils::Terminate();
return;
}

//This should return TRUE but it giving me false.
bool bChild = nodeProperties->hasChildNodes();

Can any one please tell me where i am going wrong while parsing the
following XML. The XML file is UNICODE format.

<?xml version="1.0" encoding="UTF-16"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>My XML File</comment>
<entry key="KEY2">京 喂</entry>
<entry key="KEY1">京 京 喂</entry>
<entry key="KEY5">京 京 喂</entry>
<entry key="KEY4">京 京</entry>
<entry key="KEY3">京 京 喂</entry>
</properties>

I also have attached the XML file with this message also.
http://www.nabble.com/user-files/235865/Chinese.xml Chinese.xml

With Regards,
Ghazanfar
-- 
View this message in context: 
http://www.nabble.com/XML-DTD-Validation-C%2B%2B-tf2219163.html#a6146889
Sent from the Xerces - C - Users forum at Nabble.com.