BeanoEFC Posted February 11, 2012 Share Posted February 11, 2012 Hey Everyone, I have been given an assignment where i am given an XML file and i need to parse it. The XML is in the following format: <?xml version="1.0"?> <title>Library</title> <library> <book id="1"> <author>J.K.Rowling</author> <name>Harry Potter and the Philosopher's Stone</name> </book> <book id="2"> <author>J.K.Rowling</author> <name>Harry Potter and the Chamber of Secrets</name> </book> </library> The problem i have is when i try an parse this XML, with SimpleXML, i get the following error parser error : Extra content at the end of the document The source of this error is due to there being no root node. This has left me in a bit of a predicament. Is there anyway of parsing XML in this format without the root node being added? Regards, -Ben Quote Link to comment https://forums.phpfreaks.com/topic/256918-xml-parse-error/ Share on other sites More sharing options...
requinix Posted February 11, 2012 Share Posted February 11, 2012 Yes, but first you should ask your teacher/professor whether the malformed XML was intentional and how you should deal with it. [edit] And whether you're supposed to write your own XML parser or what. I would expect so. Quote Link to comment https://forums.phpfreaks.com/topic/256918-xml-parse-error/#findComment-1317126 Share on other sites More sharing options...
BeanoEFC Posted February 12, 2012 Author Share Posted February 12, 2012 Thanks for the reply requinix. Yes, the malformed XML is intentional. Any pointers or tutorial links to make an XML parser? Regards, -Ben Quote Link to comment https://forums.phpfreaks.com/topic/256918-xml-parse-error/#findComment-1317172 Share on other sites More sharing options...
requinix Posted February 12, 2012 Share Posted February 12, 2012 I can give pointers, sure, but I don't know what all you've been taught. Your teacher wouldn't ask you to write a parser unless s/he gave instructions on how to do so. So now, (a) did the teacher tell you how to do it and (b) are you sure you're supposed to? Quote Link to comment https://forums.phpfreaks.com/topic/256918-xml-parse-error/#findComment-1317175 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.