I have a question which I have struggled four hours without solution, can anyone kindly give some advice, now it is busy exam time and i don't have more time for figuring this out.
I have an example xml file as follows: <?xml version='1.0' encoding='UTF-8'?> <test> <book> <title>learn java</title> <author>tina</author> </book> <book> <title>c++</title> <author>peter</author> </book> </test>
I convert the TestElement (<test> <book> <title>learn java</title> <author>tina</author> </book> <book> <title>c++</title> <author>peter</author> </book> </test> into a String and save the string in a table of MYSQL, but when I extract the String out of the table, I don't know how to convert it back as an element of xml file. I build a new XML file, tried to add the String as an element but failed, so the String can't be parsed as an Element.
Then I convert the whole xml file as a String and tried to save it into a table, but got error message. Seems db has problem to save the first line of xml file which is <?xml version='1.0' encoding='UTF-8'?>.
It's kind of urgent, Thanks a lot for any help!! [ April 11, 2006: Message edited by: marshal ma ]
Well. It seems you really wanted to serialize some book objects in either a database or an XML file but have given up on that route. If you wanted to go back there I would suggest posting code.
As far as your saving the XML string failing goes you should be using PreparedStatements and the problem would go away likely. The problem is most likely being caused by an unescaped ' issue in your String. It could also be that the value is being truncated... you should be storing the String into a CLOB (MySQL Text type) field and not a VARCHAR field.
Also I am 99.99% sure that you should be using " and not ' in your XML properties. I am pretty sure ' is not valid XML. So don't do that either.
If you have further problems please post some relevent code showing where you are stuck along with any relevent error messages you get. Please do not post all your code or a whole stack trace just the relevent portions would be enough to help you.
Joined: May 31, 2004
Thank you so much Maximilian Xavier Stocker!
Somehow I figured it out by just adding <?xml version="1.0" encoding..?> to that String extracted from database so the new String is an xml format and I can parse it.
I did define the feild as TEXT but not VARCHAR, but I didn't use PreparedStatement which may work as you said.
Well, the xml was built by an API which make each beginning as <?xml version='1.0'...> but not using "". I did not know why they use that. I did check the XML specification and found either "" or ''are fine for it.
Anyway, thanks for your kindly help! I really appreciate that!