I'm using kXML in my Blackberry application using Java. I want to create a string that has the xml information I need for testing purposes.
Any guidance?
For example:
String theXML = @"
<xml>
</xml>";
I'm using kXML in my Blackberry application using Java. I want to create a string that has the xml information I need for testing purposes.
Any guidance?
For example:
String theXML = @"
<xml>
</xml>";
There is no easy answer. You need to represent it as a regular Java String literal with backslash escaping for tabs, newlines, double quotes, backslashes and so on.
Your IDE may offer you some support in adding the escaping. Otherwise, you may need to do it by hand.
My advice is that if you have a lot of XML you'd be better off reading it from a file instead of embedding it in your Java code, or (as @Thilo reminds me) putting it in a resource that you can access using Class.getResourceAsStream(path)
You seem to have mixed in some objective-c in your java code. String literals only need to be surrounded with double quotes.
String the Xml = "blah";
Stephen C just posted so I wont duplicate what he wrote :)
I'm not familiar with kXML, but in Java, there is unfortunately no easy way to put inline XML. Java doesn't have an easy multiline-string syntax.
The best option, if the XML is long, is often to put it in a separate file, and have your Java program read that file. Or if the XML isn't terribly long, you can just do it this way -- ugly, but workable for shorter strings:
String theXML = "<xml>" +
"<tag1 attr='hi' />" +
"<tag2 attr='bye' />" +
"</xml>";