Unable to parse XML file


#1

I want to parse simple XML file using xerces, for that I download ‘xerces-c-3.1.4’. From their sample code I did the DomPrint program in visual studio 2013.

here is my code:


#include <xercesc/util/PlatformUtils.hpp>
#include "xercesc/util/PlatformUtils.hpp"

#include "D:\xecerces_download\xerces-c-3.1.4\src\xercesc\util\PlatformUtils.hpp"
#include"D:\xecerces_download\xerces-c-3.1.4\src\xercesc\framework\StdOutFormatTarget.cpp"
#include"D:\xecerces_download\xerces-c-3.1.4\src\xercesc\framework\LocalFileFormatTarget.cpp"


#include <xercesc/dom/DOM.hpp>

#include <xercesc/framework/StdOutFormatTarget.hpp>
#include <xercesc/framework/LocalFileFormatTarget.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/util/XMLUni.hpp>

#include "DOMTreeErrorReporter.hpp"
#include "DOMPrintFilter.hpp"
#include "DOMPrintErrorHandler.hpp"
#include <xercesc/util/OutOfMemoryException.hpp>

#include <string.h>
#include <stdlib.h>


// ---------------------------------------------------------------------------
static char*                    gXmlFile = 0;
static bool                     gDoNamespaces = false;
static bool                     gDoSchema = false;
static bool                     gSchemaFullChecking = false;
static bool                     gDoCreate = false;

static char*                    goutputfile = 0;
static char*                    gXPathExpression = 0;

// options for DOMLSSerializer's features
static XMLCh*                   gOutputEncoding = 0;

static bool                     gSplitCdataSections = true;
static bool                     gDiscardDefaultContent = true;
static bool                     gUseFilter = false;
static bool                     gFormatPrettyPrint = false;
static bool                     gWriteBOM = false;

static XercesDOMParser::ValSchemes    gValScheme = XercesDOMParser::Val_Auto;


//	Prototypes for internally used functions
void usage();


// ---------------------------------------------------------------------------
//
//  Usage()
//
// ---------------------------------------------------------------------------
void usage()
{
	XERCES_STD_QUALIFIER cout << "
Usage:
"
		"    DOMPrint [options] <XML file>

"
		"This program invokes the DOM parser, and builds the DOM tree.
"
		"It then asks the DOMLSSerializer to serialize the DOM tree.
"
		"Options:
"
		"    -e          create entity reference nodes. Default is no expansion.
"
		"    -v=xxx      Validation scheme [always | never | auto*].
"
		"    -n          Enable namespace processing. Default is off.
"
		"    -s          Enable schema processing. Default is off.
"
		"    -f          Enable full schema constraint checking. Defaults is off.
"
		"    -wenc=XXX   Use a particular encoding for output. Default is
"
		"                the same encoding as the input XML file. UTF-8 if
"
		"                input XML file has not XML declaration.
"
		"    -wfile=xxx  Write to a file instead of stdout.
"
		"    -wscs=xxx   Enable/Disable split-cdata-sections.      Default on
"
		"    -wddc=xxx   Enable/Disable discard-default-content.   Default on
"
		"    -wflt=xxx   Enable/Disable filtering.                 Default off
"
		"    -wfpp=xxx   Enable/Disable format-pretty-print.       Default off
"
		"    -wbom=xxx   Enable/Disable write Byte-Order-Mark      Default off
"
		"    -xpath=xxx  Prints only the nodes matching the given XPath.
"
		"    -?          Show this help.

"
		"  * = Default if not provided explicitly.

"
		"The parser has intrinsic support for the following encodings:
"
		"    UTF-8, US-ASCII, ISO8859-1, UTF-16[BL]E, UCS-4[BL]E,
"
		"    WINDOWS-1252, IBM1140, IBM037, IBM1047.
"
		<< XERCES_STD_QUALIFIER endl;
}

// ---------------------------------------------------------------------------
//
//  main
//
// ---------------------------------------------------------------------------
int main(int argC, char* argV[])
{
	int retval = 0;

	// Initialize the XML4C2 system
	try
	{
		XMLPlatformUtils::Initialize();
	}

	catch (const XMLException &toCatch)
	{
		XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.
"
			<< "  Exception message:"
			<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
		return 1;
	}

	// Check command line and extract arguments.
	if (argC < 2)
	{
		usage();
		XMLPlatformUtils::Terminate();
		return 1;
	}

	// See if non validating dom parser configuration is requested.
	int parmInd;
	for (parmInd = 1; parmInd < argC; parmInd++)
	{
		// Break out on first parm not starting with a dash
		if (argV[parmInd][0] != '-')
			break;

		// Watch for special case help request
		if (!strcmp(argV[parmInd], "-?"))
		{
			usage();
			XMLPlatformUtils::Terminate();
			return 2;
		}
		else if (!strncmp(argV[parmInd], "-v=", 3)
			|| !strncmp(argV[parmInd], "-V=", 3))
		{
			const char* const parm = &argV[parmInd][3];

			if (!strcmp(parm, "never"))
				gValScheme = XercesDOMParser::Val_Never;
			else if (!strcmp(parm, "auto"))
				gValScheme = XercesDOMParser::Val_Auto;
			else if (!strcmp(parm, "always"))
				gValScheme = XercesDOMParser::Val_Always;
			else
			{
				XERCES_STD_QUALIFIER cerr << "Unknown -v= value: " << parm << XERCES_STD_QUALIFIER endl;
				XMLPlatformUtils::Terminate();
				return 2;
			}
		}
		else if (!strcmp(argV[parmInd], "-n")
			|| !strcmp(argV[parmInd], "-N"))
		{
			gDoNamespaces = true;
		}
		else if (!strcmp(argV[parmInd], "-s")
			|| !strcmp(argV[parmInd], "-S"))
		{
			gDoSchema = true;
		}
		else if (!strcmp(argV[parmInd], "-f")
			|| !strcmp(argV[parmInd], "-F"))
		{
			gSchemaFullChecking = true;
		}
		else if (!strcmp(argV[parmInd], "-e")
			|| !strcmp(argV[parmInd], "-E"))
		{
			gDoCreate = true;
		}
		else if (!strncmp(argV[parmInd], "-wenc=", 6))
		{
			// Get out the encoding name
			gOutputEncoding = XMLString::transcode(&(argV[parmInd][6]));
		}
		else if (!strncmp(argV[parmInd], "-wfile=", 7))
		{
			goutputfile = &(argV[parmInd][7]);
		}
		else if (!strncmp(argV[parmInd], "-wddc=", 6))
		{
			const char* const parm = &argV[parmInd][6];

			if (!strcmp(parm, "on"))
				gDiscardDefaultContent = true;
			else if (!strcmp(parm, "off"))
				gDiscardDefaultContent = false;
			else
			{
				XERCES_STD_QUALIFIER cerr << "Unknown -wddc= value: " << parm << XERCES_STD_QUALIFIER endl;
				XMLPlatformUtils::Terminate();
				return 2;
			}

		}
		else if (!strncmp(argV[parmInd], "-wscs=", 6))
		{
			const char* const parm = &argV[parmInd][6];

			if (!strcmp(parm, "on"))
				gSplitCdataSections = true;
			else if (!strcmp(parm, "off"))
				gSplitCdataSections = false;
			else
			{
				XERCES_STD_QUALIFIER cerr << "Unknown -wscs= value: " << parm << XERCES_STD_QUALIFIER endl;
				XMLPlatformUtils::Terminate();
				return 2;
			}
		}
		else if (!strncmp(argV[parmInd], "-wflt=", 6))
		{
			const char* const parm = &argV[parmInd][6];

			if (!strcmp(parm, "on"))
				gUseFilter = true;
			else if (!strcmp(parm, "off"))
				gUseFilter = false;
			else
			{
				XERCES_STD_QUALIFIER cerr << "Unknown -wflt= value: " << parm << XERCES_STD_QUALIFIER endl;
				XMLPlatformUtils::Terminate();
				return 2;
			}
		}
		else if (!strncmp(argV[parmInd], "-wfpp=", 6))
		{
			const char* const parm = &argV[parmInd][6];

			if (!strcmp(parm, "on"))
				gFormatPrettyPrint = true;
			else if (!strcmp(parm, "off"))
				gFormatPrettyPrint = false;
			else
			{
				XERCES_STD_QUALIFIER cerr << "Unknown -wfpp= value: " << parm << XERCES_STD_QUALIFIER endl;
				XMLPlatformUtils::Terminate();
				return 2;
			}
		}
		else if (!strncmp(argV[parmInd], "-wbom=", 6))
		{
			const char* const parm = &argV[parmInd][6];

			if (!strcmp(parm, "on"))
				gWriteBOM = true;
			else if (!strcmp(parm, "off"))
				gWriteBOM = false;
			else
			{
				XERCES_STD_QUALIFIER cerr << "Unknown -wbom= value: " << parm << XERCES_STD_QUALIFIER endl;
				XMLPlatformUtils::Terminate();
				return 2;
			}
		}
		else if (!strncmp(argV[parmInd], "-xpath=", 7))
		{
			gXPathExpression = &(argV[parmInd][7]);
		}
		else
		{
			XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[parmInd]
				<< "', ignoring it.
" << XERCES_STD_QUALIFIER endl;
		}
	}

	if (parmInd + 1 != argC)
	{
		usage();
		XMLPlatformUtils::Terminate();
		return 1;
	}
	gXmlFile = argV[parmInd];


	//
	XercesDOMParser *parser = new XercesDOMParser;
	parser->setValidationScheme(gValScheme);
	parser->setDoNamespaces(gDoNamespaces);
	parser->setDoSchema(gDoSchema);
	parser->setHandleMultipleImports(true);
	parser->setValidationSchemaFullChecking(gSchemaFullChecking);
	parser->setCreateEntityReferenceNodes(gDoCreate);

	DOMTreeErrorReporter *errReporter = new DOMTreeErrorReporter();
	parser->setErrorHandler(errReporter);

	
	//
	bool errorsOccured = false;
	try
	{
		parser->parse(gXmlFile);
	}
	catch (const OutOfMemoryException&)
	{
		XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
		errorsOccured = true;
	}
	catch (const XMLException& e)
	{
		XERCES_STD_QUALIFIER cerr << "An error occurred during parsing
   Message: "
			<< StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
		errorsOccured = true;
	}

	catch (const DOMException& e)
	{
		const unsigned int maxChars = 2047;
		XMLCh errText[maxChars + 1];

		XERCES_STD_QUALIFIER cerr << "
DOM Error during parsing: '" << gXmlFile << "'
"
			<< "DOMException code is:  " << e.code << XERCES_STD_QUALIFIER endl;

		if (DOMImplementation::loadDOMExceptionMsg(e.code, errText, maxChars))
			XERCES_STD_QUALIFIER cerr << "Message is: " << StrX(errText) << XERCES_STD_QUALIFIER endl;

		errorsOccured = true;
	}

	catch (...)
	{
		XERCES_STD_QUALIFIER cerr << "An error occurred during parsing
 " << XERCES_STD_QUALIFIER endl;
		errorsOccured = true;
	}

	// If the parse was successful, output the document data from the DOM tree
	if (!errorsOccured && !errReporter->getSawErrors())
	{
		DOMPrintFilter   *myFilter = 0;

		try
		{
			// get a serializer, an instance of DOMLSSerializer
			XMLCh tempStr[3] = { chLatin_L, chLatin_S, chNull };
			DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
			DOMLSSerializer   *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
			DOMLSOutput       *theOutputDesc = ((DOMImplementationLS*)impl)->createLSOutput();

			// set user specified output encoding
			theOutputDesc->setEncoding(gOutputEncoding);

			// plug in user's own filter
			if (gUseFilter)
			{
				myFilter = new DOMPrintFilter(DOMNodeFilter::SHOW_ELEMENT |
					DOMNodeFilter::SHOW_ATTRIBUTE |
					DOMNodeFilter::SHOW_DOCUMENT_TYPE);
				theSerializer->setFilter(myFilter);
			}

			// plug in user's own error handler
			DOMErrorHandler *myErrorHandler = new DOMPrintErrorHandler();
			DOMConfiguration* serializerConfig = theSerializer->getDomConfig();
			serializerConfig->setParameter(XMLUni::fgDOMErrorHandler, myErrorHandler);

			// set feature if the serializer supports the feature/mode
			if (serializerConfig->canSetParameter(XMLUni::fgDOMWRTSplitCdataSections, gSplitCdataSections))
				serializerConfig->setParameter(XMLUni::fgDOMWRTSplitCdataSections, gSplitCdataSections);

			if (serializerConfig->canSetParameter(XMLUni::fgDOMWRTDiscardDefaultContent, gDiscardDefaultContent))
				serializerConfig->setParameter(XMLUni::fgDOMWRTDiscardDefaultContent, gDiscardDefaultContent);

			if (serializerConfig->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, gFormatPrettyPrint))
				serializerConfig->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, gFormatPrettyPrint);

			if (serializerConfig->canSetParameter(XMLUni::fgDOMWRTBOM, gWriteBOM))
				serializerConfig->setParameter(XMLUni::fgDOMWRTBOM, gWriteBOM);

			
			XMLFormatTarget *myFormTarget;
			if (goutputfile)
				myFormTarget = new LocalFileFormatTarget(goutputfile);
			else
				myFormTarget = new StdOutFormatTarget();
			theOutputDesc->setByteStream(myFormTarget);

			// get the DOM representation
			DOMDocument *doc = parser->getDocument();

			//
			// do the serialization through DOMLSSerializer::write();
			//
			if (gXPathExpression != NULL)
			{
				XMLCh* xpathStr = XMLString::transcode(gXPathExpression);
				DOMElement* root = doc->getDocumentElement();
				try
				{
					DOMXPathNSResolver* resolver = doc->createNSResolver(root);
					DOMXPathResult* result = doc->evaluate(
						xpathStr,
						root,
						resolver,
						DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
						NULL);

					XMLSize_t nLength = result->getSnapshotLength();
					for (XMLSize_t i = 0; i < nLength; i++)
					{
						result->snapshotItem(i);
						theSerializer->write(result->getNodeValue(), theOutputDesc);
					}

					result->release();
					resolver->release();
				}
				catch (const DOMXPathException& e)
				{
					XERCES_STD_QUALIFIER cerr << "An error occurred during processing of the XPath expression. Msg is:"
						<< XERCES_STD_QUALIFIER endl
						<< StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
					retval = 4;
				}
				catch (const DOMException& e)
				{
					XERCES_STD_QUALIFIER cerr << "An error occurred during processing of the XPath expression. Msg is:"
						<< XERCES_STD_QUALIFIER endl
						<< StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
					retval = 4;
				}
				XMLString::release(&xpathStr);
			}
			else
				theSerializer->write(doc, theOutputDesc);

			theOutputDesc->release();
			theSerializer->release();

			delete myFormTarget;
			delete myErrorHandler;

			if (gUseFilter)
				delete myFilter;

		}
		catch (const OutOfMemoryException&)
		{
			XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
			retval = 5;
		}
		catch (XMLException& e)
		{
			XERCES_STD_QUALIFIER cerr << "An error occurred during creation of output transcoder. Msg is:"
				<< XERCES_STD_QUALIFIER endl
				<< StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
			retval = 4;
		}

	}
	else
		retval = 4;

	
	delete errReporter;

	delete parser;

	XMLString::release(&gOutputEncoding);

	XMLPlatformUtils::Terminate();

	return retval;
}

which showing errors: 1. Cannot open include file: ‘xercesc/util/PlatformUtils.hpp’: No such file or directory
2. IntelliSense: ‘operator=’ must be a member function
3. IntelliSense: cannot open source file “xercesc/util/PanicHandler.hpp”
4. IntelliSense: cannot open source file “xercesc/util/XercesDefs.hpp” and many more.

for that 1.I added respective .hpp file 2. set precompiled header–>no 3. set path " D:\xecerces_download\xerces-c-3.1.4\src\xercesc" in project–>property–>c/c+±->general 4. project–>property–>linker–>input–>xerces-c_3D.lib;%(AdditionalDependencies)

still so many errors are there,Can you please help me to sort it out?


#2

In practice, it’s completely unacceptable to use absolute include paths. And it’s even more unacceptable to include “.CPP” files. These are code, and not headers!

You should always set up your project and the include paths properly, so that you can include the required headers like this:


#include <xercesc/util/PlatformUtils.hpp>

So you should remove the following lines:


#include "xercesc/util/PlatformUtils.hpp"
...
#include "D:\xecerces_download\xerces-c-3.1.4\src\xercesc\util\PlatformUtils.hpp"
#include"D:\xecerces_download\xerces-c-3.1.4\src\xercesc\framework\StdOutFormatTarget.cpp"
#include"D:\xecerces_download\xerces-c-3.1.4\src\xercesc\framework\LocalFileFormatTarget.cpp"

If it then does not work, you have to adjust your project setup.


(You might also have to remove


#include "DOMTreeErrorReporter.hpp"
#include "DOMPrintFilter.hpp"
#include "DOMPrintErrorHandler.hpp"

but this depends: Are these files part of your project, or are they part of xerces?)


A side note: Did you use xerces for a particular reason? It might be a bit complicated to use. If your goal is only to parse some XML, then there are many alternatives. I think that “header-only” libraries like https://github.com/leethomason/tinyxml2 are far easier to integrate. You can just copy the single header and cpp file into your project, and include it as
#include "tinyxml2.h"
But of course, if you want to use xerces, then you’ll likely get this running as well.


#3

thanks Marco…!!!

     I followed all your suggestions and removed that .hpp and .cpp file, but still errors are unchanged. It is again showing errors to access all included .hpp  file.

#include “DOMTreeErrorReporter.hpp”
#include “DOMPrintFilter.hpp”
#include “DOMPrintErrorHandler.hpp” all these file are part of xerces itself.
Actually I want to parse very large XML file, so I was doubtful about “tinyxml”. My task is to run on xerces.


#4

I downloaded Xerces and tried this out: The files
#include “DOMTreeErrorReporter.hpp”
#include “DOMPrintFilter.hpp”
#include “DOMPrintErrorHandler.hpp”
are part of the sample (namely, of the “DomPrint” sample). They are not part of the Xerces library itself.

I just opened
\xerces-c-3.1.4\projects\Win32\VC14\xerces-all\xerces-all.sln
and the DomPrint example compiled properly.

Did you create a new, own project where you want to use Xerces, or did you really try to compile the original “DomPrint” sample in Xerces (using the predefined “.sln” files)?

If you want to create a new, own project: The “DomPrint” example seems to be rather complex. I’m not sure about the “best” example to get started with Xerces, but one of the first websearch results for something like minimal xerces xml parse example led me to Linux Tutorial: Parsing XML with Xerces-C C++ API , and this compiled and ran smoothly here (although I have not read the code - just copied+pasted it, for testing).

In any case, you’ll have to add the Xerces source folder in "C/C++ -> General -> Additional include directories"
(This source folder may be C:\xerces-c-3.1.4\src\)

And you’ll have to add the “.lib” file that was created by building the “XercesLib” project, in "Linker -> Input -> Additional Dependencies"
(This library may be C:\xerces-c-3.1.4\Build\Win32\VC14\Debug\xerces-c_3D.lib

When running the resulting .EXE file, the Xerces DLL has to be visible, e.g. in the same directory.


#5

I create new project and now I am doing createDomDocument program instead of DomPrint. according to your suggestions I made changes and now now compile time error is there. but while running it is showing error: " Unable to start program C:\Users\590942\documents\VS1013\projects
ewXerces\Debug\xerces.exe"
system can not find file specified…:rolleyes:


#6

As you said tinyXML is simple one, so I tried it with the help of this link–>Getting started with TinyXml | technical-recipes.com

It is not showing any error but not parsing my given xml file. It is only doing for their sample code. sorry, I know I am making you trouble ,but I want to parse my XML file with any of it(1.xerces 2TinyXml)

First I download the tinyxml_2_6_2.zip file.In that xmlTest.cpp file was there, so I just replace their dream.xml file with my xml file (including path)and it is showing me output:

output
[spoiler]
** Demo doc read from disk: **

** Printing via doc.Print **

<?xml version="1.0" standalone="no" ?> Go to the Toy store! Do bills Look for Evil Dinosaurs! ** Printing via TiXmlPrinter ** <?xml version="1.0" standalone="no" ?> Go to the Toy store! Do bills Look for Evil Dinosaurs!

** Demo doc processed: **

<?xml version="1.0" standalone="no" ?> Go to the Toy store! Talk to: Do bills [pass] Root element exists. [1][1] [pass] Root element value is 'ToDo'. [ToDo][ToDo] [pass] First child exists & is a comment. [1][1] [pass] Sibling element exists & is an element. [1][1] [pass] Value is 'Item'. [Item][Item] [pass] First child exists. [1][1] [pass] Value is 'Go to the'. [Go to the][Go to the]

** Iterators. **
[pass] Top level nodes, using First / Next. [3][3]
[pass] Top level nodes, using Last / Previous. [3][3]
[pass] Top level nodes, using IterateChildren. [3][3]
[pass] Children of the ‘ToDo’ element, using First / Next. [3][3]
[pass] ‘Item’ children of the ‘ToDo’ element, using First/Next. [3][3]
[pass] ‘Item’ children of the ‘ToDo’ element, using Last/Previous. [3][3]
[pass] Error row [3][3]
[pass] Error column [17][17]
[pass] Query attribute: int as double [0][0]
[pass] Query attribute: int as double [1][1]
[pass] Query attribute: double as double [2][2]
[pass] Query attribute: double as int [0][0]
[pass] Query attribute: double as int [2][2]
[pass] Query attribute: not a number [2][2]
[pass] Query attribute: does not exist [1][1]
[pass] Attribute round trip. c-string. [strValue][strValue]
[pass] Attribute round trip. int. [1][1]
[pass] Attribute round trip. double. [-1][-1]
[pass] Location tracking: Tab 8: room row [1][1]
[pass] Location tracking: Tab 8: room col [49][49]
[pass] Location tracking: Tab 8: doors row [1][1]
[pass] Location tracking: Tab 8: doors col [55][55]
[pass] Location tracking: Declaration row [1][1]
[pass] Location tracking: Declaration col [5][5]
[pass] Location tracking: room row [1][1]
[pass] Location tracking: room col [45][45]
[pass] Location tracking: doors row [1][1]
[pass] Location tracking: doors col [51][51]
[pass] Location tracking: Comment row [2][2]
[pass] Location tracking: Comment col [3][3]
[pass] Location tracking: text row [3][3]
[pass] Location tracking: text col [24][24]
[pass] Location tracking: door0 row [3][3]
[pass] Location tracking: door0 col [5][5]
[pass] Location tracking: door1 row [4][4]
[pass] Location tracking: door1 col [5][5]

** UTF-8 **
WARNING: File ‘utf8test.xml’ not found.
(Are you running the test from the wrong directory?)
Could not test UTF-8 functionality.

** Copy and Assignment **
[pass] Copy/Assign: element copy #1. [element][element]
[pass] Copy/Assign: element copy #2. [value][value]
[pass] Copy/Assign: element assign #1. [element][element]
[pass] Copy/Assign: element assign #2. [value][value]
[pass] Copy/Assign: element assign #3. [1][1]
[pass] Copy/Assign: comment copy. [comment][comment]
[pass] Copy/Assign: comment assign. [comment][comment]
[pass] Copy/Assign: unknown copy. [[unknown]][[unknown]]
[pass] Copy/Assign: unknown assign. [[unknown]][[unknown]]
[pass] Copy/Assign: text copy. [TextNode][TextNode]
[pass] Copy/Assign: text assign. [TextNode][TextNode]
[pass] Copy/Assign: declaration copy. [UTF-8][UTF-8]
[pass] Copy/Assign: text assign. [UTF-8][UTF-8]
[pass] GetText() normal use. [This is text][This is text]
[pass] GetText() contained element. [1][1]
[pass] GetText() partial. [This is ][This is ]

the rules! ...since I make symbolic puns]]>

[pass] CDATA parse.
[pass] CDATA copy.
[pass] CDATA with all bytes #1.

<![CDATA[I am > the rules! ...since I make symbolic puns]]>

[pass] CDATA parse. [ 1480107 ]
[pass] CDATA copy. [ 1480107 ]

** Fuzzing… **
** Fuzzing Complete. **

** Bug regression tests **
[pass] Test InsertBeforeChild on empty node. [1][1]
[pass] Test InsertAfterChild on empty node. [1][1]
[pass] Basic TiXmlString test. [Hello World!][Hello World!]
[pass] Entity transformation: read.
[pass] Entity transformation: write.
[pass] dot in element attributes and names [0][0]
[pass] Entity with one digit. [1][1]
[pass] Entity with one digit. [1.1 Start easy ignore fin thickness
][1.1 Start easy ignore fin thickness
]
[pass] Correct value of unknown. [!DOCTYPE PLAY SYSTEM ‘play.dtd’][!DOCTYPE PLAY
SYSTEM ‘play.dtd’]
[pass] Comment formatting. [ Somewhat ][ Somewhat ]
[pass] White space kept. [ This has leading and trailing space ][ This has leadi
ng and trailing space ]
[pass] White space kept. [This has internal space][This has internal space]
[pass] White space kept. [ This has leading, trailing, and internal space ][ Th
is has leading, trailing, and internal space ]
[pass] White space condensed. [This has leading and trailing space][This has lea
ding and trailing space]
[pass] White space condensed. [This has internal space][This has internal space]

[pass] White space condensed. [This has leading, trailing, and internal space][T
his has leading, trailing, and internal space]
[pass] Parsing repeated attributes. [1][1]
[pass] Embedded null throws error. [1][1]
[pass] ISO-8859-1 Parsing. [C÷ntΣnt▀Σ÷ⁿ─╓▄][C÷ntΣnt▀Σ÷ⁿ─╓▄]
[pass] Empty document error TIXML_ERROR_DOCUMENT_EMPTY [12][12]
[pass] Empty tinyxml string compare equal [1][1]
[pass] Empty tinyxml string compare equal [1][1]
[pass] Test safe error return. [0][0]
[pass] Low entities. [♫][♫]

[pass] Throw error with bad end quotes. [1][1]
[pass] Document only at top level. [1][1]
[pass] Document only at top level. [15][15]
[pass] Missing end tag at end of input [1][1]
[pass] Missing end tag with trailing whitespace [1][1]
[pass] Comments ignore entities.
[pass] Comments ignore entities.
[pass] Comments iterate correctly. [3][3]
[pass] Handle end tag whitespace [0][0]
[pass] Infinite loop test. [1][1]
[pass] Odd XML parsing. [tag][tag]

Pass 99, Fail 0
Press any key to continue . . .
[/spoiler]

what changes should I make, means I will get my expected output(i.e parsed XML file)


#7

Note that I referred to TinyXML-2 from https://github.com/leethomason/tinyxml2 , which is not the same as “TinyXML” (even when the version number of TinyXML is 2.6.2, in this case). (Yes, it’s confusing…)

However, it seems like you managed to compile the “xmlTest.cpp” with TinyXML, and this file contains a set of tests, and they are all passing. So basically, you should be able to load and print the XML with


TiXmlDocument doc( "demotest.xml" );
bool loadOkay = doc.LoadFile();
if ( !loadOkay )
{
    printf( "Could not load test file 'demotest.xml'. Error='%s'. Exiting.
", doc.ErrorDesc() );
}
doc.Print( stdout );

I’m not sure what you expect.


#8

If we go through code they use so many .xml file like utf8test.xml,utf8testverify.xml,passages.xml, test5.xml, test6.xml etc. So I am not getting the use of it. They parse their demotest.xml,Instead of that I want to parse my xml file so accordingly, what changes should I make in this code? cause I don’t know what are these passages.xml,test5.xml,test6.xml and so on

I replace my xml file with demotest.xml & I am getting output as:

output
[spoiler]
** Demo doc read from disk: **

** Printing via doc.Print **

<?xml version="1.0" standalone="no" ?> Go to the Toy store! Do bills Look for Evil Dinosaurs! ** Printing via TiXmlPrinter ** <?xml version="1.0" standalone="no" ?> Go to the Toy store! Do bills Look for Evil Dinosaurs!

** Demo doc processed: **

<?xml version="1.0" standalone="no" ?> Go to the Toy store! Talk to: Do bills [pass] Root element exists. [1][1] [pass] Root element value is 'ToDo'. [ToDo][ToDo] [pass] First child exists & is a comment. [1][1] [pass] Sibling element exists & is an element. [1][1] [pass] Value is 'Item'. [Item][Item] [pass] First child exists. [1][1] [pass] Value is 'Go to the'. [Go to the][Go to the]

** Iterators. **
[pass] Top level nodes, using First / Next. [3][3]
[pass] Top level nodes, using Last / Previous. [3][3]
[pass] Top level nodes, using IterateChildren. [3][3]
[pass] Children of the ‘ToDo’ element, using First / Next. [3][3]
[pass] ‘Item’ children of the ‘ToDo’ element, using First/Next. [3][3]
[pass] ‘Item’ children of the ‘ToDo’ element, using Last/Previous. [3][3]
[pass] Error row [3][3]
[pass] Error column [17][17]
[pass] Query attribute: int as double [0][0]
[pass] Query attribute: int as double [1][1]
[pass] Query attribute: double as double [2][2]
[pass] Query attribute: double as int [0][0]
[pass] Query attribute: double as int [2][2]
[pass] Query attribute: not a number [2][2]
[pass] Query attribute: does not exist [1][1]
[pass] Attribute round trip. c-string. [strValue][strValue]
[pass] Attribute round trip. int. [1][1]
[pass] Attribute round trip. double. [-1][-1]
[pass] Location tracking: Tab 8: room row [1][1]
[pass] Location tracking: Tab 8: room col [49][49]
[pass] Location tracking: Tab 8: doors row [1][1]
[pass] Location tracking: Tab 8: doors col [55][55]
[pass] Location tracking: Declaration row [1][1]
[pass] Location tracking: Declaration col [5][5]
[pass] Location tracking: room row [1][1]
[pass] Location tracking: room col [45][45]
[pass] Location tracking: doors row [1][1]
[/spoiler]

which is not the content of my xml file, means I m getting wrong output, So where we go wrong?


#9

I’m not entirely sure what you mean.

But the “xmltest.cpp” reads XML data from a string (the string is contained in the source code).
Then it writes this data into a file called “demotest.xml”.
Then it reads this file again, to verify it.

So if you just change the contents of “demotest.xml” (or use a different file name), then the data will be overwritten.

(A side note: You won’t get around reading some of the documentation and trying to understand the examples…)


#10

okay…
Now I tried TinyXML-2 from https://github.com/leethomason/tinyxml2 , I got two error:
1 unresolved externals -->then I do property->linker->system->subsystem->not set and it gets resolved
2. LNK1561: entry point must be defined --> which is unresolved one

xmlTest.cpp contained main function still it's showing this error. So should I change that previous linker setting to console/windows??

#11

Sorry, the description is really hard to follow. So now you abandoned Xerces and TinyXML, and are trying TinyXML2. OK.

Did you compile this as a library?
Or did you include this in an own project?

Taking one step back: You want to parse XML. That’s what you already did, with TinyXML. But regardless of whether you use TinyXML or TinyXML2, you will then have an XMLDocument object. What are you going to do then?


#12

Basically I have one XML file(with size 1MB) which I want to parse and do comparative study of how much time it will take to parse file with different parser. I did the same task with pugixml and rapid xml. Now I want to use any one more parser ,so I decided to go with Tinyxml2 okay?? for that, I create new project----->copy +paste the code present in testXML file—>add tinyxml2.h & tinyxml2.cpp file by add exiting item.

then I got two errors:
1 unresolved externals -->then I do setting: property->linker->system->subsystem->not set. (error gets resolved)
2. LNK1561: entry point must be defined --> which is unresolved one

I am stuck now what to do next??


#13

OK. There are several websites containing different XML benchmarks, but maybe you have a particular reason to do this.

I’m not sooo familiar with some Visual Studio settings, but when it complains about “unresolved externals”, for me, this usually means that a “.lib” is missing. And this is usually added at
Linker -> Input -> Additional Depencencies

When it says that the “entry point must be defined”, wonder which type of project you set up. It should probably have been a “Console Application” project.


#14

1.Which Additional dependancy\ .lib we have to add in this case?? I m not able to see any .lib here
2.While creating new project I select win32 console application, so if I change setting “property->linker->system->subsystem->not set” to the
“linker–>system–>subsystem–>console” it is showing errors:

  1. LNK1120: 1 unresolved externals
  2. LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

-_-:frowning:


#15

When you compile a library, you will receive a .DLL file and a .LIB file. The .LIB file is added as dependency in other projects, so that they may later (at runtime) link to the DLL.

When you’re NOT compiling a library, but instead create a standalone project where you add the .HPP and .CPP files of the XML parser, then you have to define a “main” method, and do other settings. But I don’t know whicht ones, because they are all set by default when you create a “Console Application” in Visual Studio. (I have created a few dozens of projects and worked with VS for several years, and I did not even know that the “Linker Subsystem” setting existed).

However, you said that you parsed the file with PugiXML and RapidXML. Then I’d strongly recommend to use one of these libraries that work for you.. It’s probably not worth the hassle and certainly not reasonable to “test the performance” of different libraries when the main problems are already in compiling a library.

*** Edit ***

Here is a complete Visual Studio 2013 project (including the compiled executable) that uses TinyXML2 to load the “dream.xml”.

(I will NOT do this for the ~20 other XML parser libraries that are, for example, compared at pugixml.org - Benchmark !)


#16

Thank you so much…!!! :slight_smile:

whatever TinyXml2Test.zip you send I copied it into my environment. In that tinyXMLTest.cpp contained only this much code:
#include “tinyxml2.h”

int main(int argc, char* argv[])
{
tinyxml2::XMLDocument doc;
doc.LoadFile(“dream.xml”);
printf("Loaded:
");
doc.Print();
return 0;
}

which is not sufficient I guess. still I run it, and it’s runnable code. fine…!!
1.Now I replace my xml file(i.e.Dummy_XML_1.xml) at the place of dream.xml in above mention code(before that I saved my xml file at same location where dream.xml was saved) and even after this change it is showing me same output as before(i.e parsed dream.xml) okay???

2.So I made some change again. Means whatever zip file I downloaded from https://github.com/leethomason/tinyxml2 this link, I copy the code of xmlTest.cpp and pasted it into tinyXMLTest.cpp(means at the place of above mention code) and run it, again it is runnable. okay?? then I delete that dream.xml file from that location still code was running???:eek: and again I put my XML file at that location & again it is showing me same output(i.e parsed dream.xml)…how?? no dream.xml file is present in that folder still…???(Every time I clean previous project and rebuild it.)Are you getting my problem?? I know it’s so messy/confusing/lengthy conversation but I am helpless…!!1-_-

Thanku in advance…!!


#17

This cannot be the case. Look at the Date/Time when the “.exe” was changed the last time. Look at the Visual Studio output. You are either not compiling it properly, or to a wrong directory.

So I don’t know where you placed the XML file or how you compiled the program.

Regarding 2: When you compile the original TinyXML2 project, then you have a “test.exe”, and this loads the “dream.xml” from the working directory. But it also prints parts of the “dream.xml” without loading the file. Parts of the “dream.xml” are contained in the program, as a string. Maybe this is what cofuses you here. You likely have not even read any of the source code of the TinyXML2 test.

Beyond that, sorry: I don’t know how I (or anybody else) could help you there.

And frankly: I don’t believe you when you say that you compared Pugixml and Rapidxml. You cannot have done this when you’re unable to build TinyXML2. But that’s probably not relevant.