1

I'm working on my program where I would import an XML file and scan for parser state (also Element, line number, content).

Right now, I have all the elements and line numbers stored in vectors of string and integer.

My question is, how can I scan for an attribute which at the end I would be able to indicate the root, children, and direct children? I have tried using <map> but still no clue.

Here are some examples:

enter image description here

Output will be

enter image description here

It would be easy if I used additional libraries but I would like to use the standard C/C++ library only.

kdopen
  • 8,032
  • 7
  • 44
  • 52
Krin
  • 51
  • 2
  • 6
    Don't. Use a library. XML-parsing is hard and you will get it wrong the first 1000 attempts. If you just want to learn - it's a different story though – Rostislav Oct 16 '15 at 19:17
  • 5
    please don't use screenshots of text -- just copy and paste the text and use the "source code" formatting that you get when selecting the text and clicking on the `{}` button. – Marcus Müller Oct 16 '15 at 19:20

1 Answers1

6

If you want an XML parser, use an XML parser. Simple as that. If you don't want to use an existing one, but only use the tools that C++ gives you, you'd write your own XML parser. Doing that would be insane.

And if people tell you to e.g. use regular expressions on XML: XML is not a regular language, and you'll need a lexer that understands XML, which is an XML parser. To see what happens when you try to RegEx-analyze things like HTML, see this answer.

Community
  • 1
  • 1
Marcus Müller
  • 34,677
  • 4
  • 53
  • 94