I have an XML parser that crashes on incomplete XML data. So XML data fed to it could be one of the following:
<one><two>twocontent</two</one> <a/><b/> ( the parser treats it as two root elements )
Element attributes are also handled ( though not shown above ).
Now, the problem is when I read data from socket I get data in fragments. For example:
<one>one content</two> </one>
Thus, before sending the XML to the parser I have to construct a valid XML and send it. What programming construct ( like iteration, recursion etc ) would be the best fit for this kind of scenario.
I am programming in C++.
Please help.
Are there multiple writers? Why isn’t your parser validating the XML?
Use a tree, where every node represents an element and carries with it a dirty bit. The first occurrence of the node marks it as dirty i.e. you are expecting a closing tag, unless of course the node is of the form
<a/>. Also, the first element, you encounter is the root.When you hit a dirty node, keep pushing nodes in a stack, until you hit the closing tag, when you pop the contents.