Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Okay, so I have the following code that I have modeled from online resources:

C++
std::vector<std::string> VN::XDocument::getNode()
	 {
		 std::string xmld = document;
		rapidxml::xml_document<> doc;

		std::vector<char> xml_c(xmld.begin(), xmld.end());
		xml_c.push_back('\0');
		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();

		 v.push_back(rn->first_attribute()->value());
		 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:

C++
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:
XML
<entry_list version="1.0">
<entry id="hello">
<ew>hello</ew>
<hw>hel*lo</hw>
<sound>
<wav>hello001.wav</wav>
<wpr>hu-!lO</wpr>
</sound>
<pr>hə-ˈlō, he-</pr>
<fl>noun</fl>
<in>
<il>plural</il>
<if>hellos</if>
</in>
<et>
alteration of
<it>hollo</it>
</et>
<def>
<date>1877</date>
<dt>
:an expression or gesture of greeting
<un>
used interjectionally in greeting, in answering the telephone, or to express surprise
</un>
</dt>
</def>
</entry>
<entry id="hullo">
<ew>hullo</ew>
<hw>hul*lo</hw>
<sound>
<wav>hullo001.wav</wav>
<wpr>(+)hu-!lO</wpr>
</sound>
<pr>(ˌ)hə-ˈlō</pr>
<cx>
<cl>chiefly British variant of</cl>
<ct>hello</ct>
</cx>
</entry>
</entry_list>

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
Updated 12-Mar-13 6:02am
v2
Comments
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?
—SA
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...

—SA
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.
—SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900