Click here to Skip to main content
13,046,464 members (72,209 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Okay, so I have the following code that I have modeled from online resources:

std::vector<std::string> VN::XDocument::getNode()
		 std::string xmld = document;
		rapidxml::xml_document<> doc;
		std::vector<char> xml_c(xmld.begin(), xmld.end());
		doc.parse<rapidxml::parse_declaration_node | rapidxml::parse_no_data_nodes>(&xml_c[0]);
		 std::vector<std::string> v;
		 rapidxml::xml_node<>* rn = doc.first_node();
		 return v;

Please note that "document" is a variable storing an online XML file (I didn't post the actual URL for privacy reasons...) but anyway, I call the above code from the following:

VN::XDocument x(xmlStr);
std::vector<std::string> defs = x.getNode();
std::cout << defs[0];

It's a vector because I eventually plan to read off more of the XML file.. but for now I'm just calling the first node just to make sure it works. However, every time I debug I get the following error:

Microsoft C++ exception: rapidxml::parse_error at memory location 0x0018f180..

Here's the XML file:
<entry_list version="1.0">
<entry id="hello">
<pr>hə-ˈlō, he-</pr>
alteration of
:an expression or gesture of greeting
used interjectionally in greeting, in answering the telephone, or to express surprise
<entry id="hullo">
<cl>chiefly British variant of</cl>

Anyone else ever get this? I don't know what to do! I tried everything! Please help. Thanks in advanced.

BTW, I'm a C++ newbie.
Posted 12-Mar-13 5:23am
Updated 12-Mar-13 6:02am
Sergey Alexandrovich Kryukov 12-Mar-13 11:24am
What's on input when you get this exception?
How do you know that XML is well-formed and valid?
RadXPictures 12-Mar-13 11:55am
I would imagine the XML is valid because I originally had parsed it using Linq XDocument in C# and it worked fine. But for cross-platform purposes I switched to C++... Nothing outputs when the exception is thrown. It immediately returns to Visual Studio, opens up rapidxml.cpp (line 1409) and shows a message box displaying the error. I then have to manually stop the debugger and return to the coding window.
Sergey Alexandrovich Kryukov 12-Mar-13 13:31pm
I would double-check. It sounds weird. Anyway, I cannot tell anything until I see some minimalistic XML sample which fails to parse.

For you information, C# is also cross-platform, with stricter level of standardization through ECMA and ISO standards for CLR, C# and C++/CLI. .NET applications written in a compatible way (and XML support is of course compatible part of FCL) actually work on a good number of systems without recompilation.

And there is a good number of other C++ XML parsers...

RadXPictures 12-Mar-13 11:59am
Oh... and also, the debugger seems to say something about m_name and m_value in the xml_node being bad pointers (bad ptr)
Sergey Alexandrovich Kryukov 12-Mar-13 13:32pm
Please, show the relevant XML sample causing the problem, try to minimize it as much as you can.
RadXPictures 14-Mar-13 11:58am
I just posted it..
Sergey Alexandrovich Kryukov 14-Mar-13 12:28pm
As I can see, your XML uses Unicode, so you need to add the prolog:
<?xml version="1.0" encoding="utf-8"?>

I hope that even without prolog, you initialize you XML reader (or whatever it is) to read with proper charset, so it should not cause this problem.
Other than that, XML is correct, thank you for showing it...

RadXPictures 14-Mar-13 14:00pm
I'm sorry, but I'm fairly new to C++, but how exactly would I implement the prolog? What is a prolog?
Sergey Alexandrovich Kryukov 14-Mar-13 14:49pm
Oh, I'm sorry, I missed the formatting in my comment above, so it was invisible to you. This is the line shown in red, above. Please see now.
Look, you need to take at least a quick look at XML standard, to get some basic ideas... and terminology...
Sergey Alexandrovich Kryukov 14-Mar-13 14:52pm
I'm afraid this fix won't help you, but it's better to observe the encoding. Who knows...

After all, I don't know how good is the RapidXML parser, but it's open source, so you can dig out where the problem is, using the full source code and the debugger...
RadXPictures 16-Mar-13 22:19pm
I think I know what the problem is... because my XML file is from an online source, it isn't reading it correctly, therefore never parsing, therefore throwing errors... I think I'm gonna try a more web-friendly language, like Python, simply because I can. Thanks for the help anyway though.
Sergey Alexandrovich Kryukov 16-Mar-13 23:13pm
I'm not sure. It shouldn't make any difference...
A language cannot be Web-friendly or not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 12 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100