Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
Validating an XML String
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="J. VerSchave, post: 559972"] I am trying to validate some XML. The XML is not in a file. It is stored in a string. i.e. String my_xml = "<XML>This is xml</XML>"; I would like to independently verify that my_xml is well formed AND it is also valid against a specified DTD. This seems easy to do if the XML were stored in a file or as a URI. However, I currently have the XML in a string. I could probably write my string to a temp file and read the file but seems like there should be a cleaner solution. I was trying to do something like this: DefaultHandler handler = new DefaultHandler(); SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(true); try { // Parse the input SAXParser saxParser = factory.newSAXParser(); saxParser.parse( my_xml, handler ); MyLogger.info("TextBodyHelper.validateTextBodyXML() - Text is Valid"); ... ... Obviously this does not work because saxParser.parse() assumes that my_xml is a file name and not the XML itself. Does anyone have any suggestions? Examples? URLs? Thanks. -j [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
Validating an XML String
Top