How to check proper XML

G

gk

my application will get a XML and store in a String variable.

String variable="a big xml string";

i want to check whether it is a valid/proper XML or not.

How do i check ?





my XML has these tags .

Example XML
===========

<note>
<to>peru</to>
<from>sadu</from>
<heading>headline</heading>
<body>do it now</body>
</note>



this is sample XML.




Now, how to check at runtime whether i am having a valid/proper
XML(this means,contains above tags) in the String variable?
 
O

Oliver Wong

gk said:
my application will get a XML and store in a String variable.

String variable="a big xml string";

i want to check whether it is a valid/proper XML or not.

How do i check ?





my XML has these tags .

Example XML
===========

<note>
<to>peru</to>
<from>sadu</from>
<heading>headline</heading>
<body>do it now</body>
</note>



this is sample XML.




Now, how to check at runtime whether i am having a valid/proper
XML(this means,contains above tags) in the String variable?

Write a schema (XSD file) or document definition (DTD file) that
describes the structure of your XML file, then use a Java parser which
performs validation as part of its parsing phase.

Here's a tutorial on writing XML schemas:

http://www.w3schools.com/schema/default.asp

- Oliver
 
R

Roedy Green

my application will get a XML and store in a String variable.

String variable="a big xml string";

i want to check whether it is a valid/proper XML or not.

How do i check ?
You need a XSD or DTD to describe the format of your file.

See http://mindprod.com/jgloss/xml.html
for various verifiers.

There is source code for a simple-minded one posted at
http://mindprod.com/jgloss/jnlp.html
for verifying jnlp a flavour of XML using an XSD schema.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top