Efficient text to xml test

I would like to write a method or class that tests to see if, for example, text that makes up a specific row/record in my Oracle DB can be succcesfully converted to xml.  I am aware that there may be special characters in text that may cause problems when converting to xml, so this is the reason for this test.  I am looking for an efficient way to run such a test.  Any ideas?
rnicholusAsked:
Who is Participating?
 
objectsCommented:
Why not instead just wrap the data in CDATA block?
0
 
aozarovCommented:
the special characters are: &, <  > ' and "
You can loop thru your text and check each caracter against a java swith statement that cotains the above characters.
char[] chars = string.toCharArray();
for (int i =; i < chars; i++)
{
char ch = chars[i];
switch (ch)
{
case '&':
case '<':
...
return false;
}
}
0
 
rnicholusAuthor Commented:
I'm not sure I even know what a CDATA block is.  Could you enlighten me?
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
aozarovCommented:
XML content that is wrapped inside CDATA will not be parsed as XML and will be left as is:
e.g.
<script>
<![CDATA[
function matchwo(a,b)
{
if (a < b && a < 0) then
   {
   return 1
   }
else
   {
   return 0
   }
}
]]>
</script>

see http://www.w3schools.com/xml/xml_cdata.asp
0
 
rnicholusAuthor Commented:
Thanks.  I will investigate this futher tommorrow (if time allows).
0
 
rnicholusAuthor Commented:
I still have not had time to invesitage this, but I will close this out anyways.  If I understand correctly, if I wrap a string inside a CDATA block, it is guaranteed to not have problems when injecting into into an XML doc.  Correct?
0
 
aozarovCommented:
Correct (to check it you can take that piece of XML and try to open in with any XML editor, Windows Explorer can also be used).
If the XML is not well formed you will get exception (try to take out the CDATA section and see the difference).
0
 
rnicholusAuthor Commented:
Thanks!
0
 
aozarovCommented:
:-)
0
 
objectsCommented:
Good to see my suggestion help you :)
0
 
rnicholusAuthor Commented:
oops.  I apologize.  I should have split the points.  Is there any way I can do this now?
0
 
objectsCommented:
0
 
rnicholusAuthor Commented:
done.  hopefully the admins will take care of this post-haste.

http://www.experts-exchange.com/Community_Support/Q_21407273.html
0
 
objectsCommented:
thanks :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.