1

The whole day I've tried to find some way to make XML queries in C++, but with no success. I don't have much experience from XML and the last time I've made something bigger in C++ was about 7 years ago, so I don't really know what's going on there nowadays.

What I would like to do is to be able to search a XML file for some words or letters and in return get that specific element or elements which have that specific text. For example say we have a XML like this:

<parent>
<node num="123" otherattrib="example"> This node has some text </node>
<node num="234" otherattrib=""> Something here as well </node>
</parent>

And I'd like to query the xml for string "text" and it would return the node with the attribute num="123".

Is there a good way to do that in C++? Also are there any good libraries for this?

Edit: The platform I'm working on will be Windows for now.

zaplec
  • 1,681
  • 4
  • 23
  • 51
  • What you may need to do is trying to parse the XML file to get those tags and fields with values.This thread http://stackoverflow.com/questions/170686/best-open-xml-parser-for-c contains some information about open source XML parsing libraries in C++. If you figure out how to use any of them, the task should be easy. BTW: our group used Xerces for XML parsing – taocp Mar 21 '13 at 15:06
  • on which platform? on Windows, you have options of MSXml COM library or you can use Xerces. For linux I am not sure, but Xerces should work there, too. There are some suggestions here: http://stackoverflow.com/questions/170686/best-open-xml-parser-for-c – Zdeslav Vojkovic Mar 21 '13 at 15:06
  • After you pick a library, you can use xpath: http://stackoverflow.com/questions/6442430/xpath-to-get-node-containing-text – 001 Mar 21 '13 at 15:07
  • Thanks. Lots of good comments already. Going to go through them and hopefully I'll find something that's suitable for me. Also I now edited the question and added the info about the platform that is windows for now. I might port the app later to Linux if I get it working as intended. – zaplec Mar 21 '13 at 15:15

0 Answers0