checking DTD when writing XML

A

Albert

Hi, is there any library out there which checks XML when writing it ?
I've tried googling, but without any result.
 
D

Donkey Hottie

Albert said:
Hi, is there any library out there which checks XML when
writing it ? I've tried googling, but without any result.

Any decent Java IDE or any XML editor does that.

What do you use to write the XML? Why?
 
R

RedGrittyBrick

Donkey said:
Any decent Java IDE or any XML editor does that.

Do you mean checking the XML is well-formed or as-you-type checking
against DTD/XSD/Schematron/RelaxNG ... ?
 
R

Roedy Green

Hi, is there any library out there which checks XML when writing it ?
I've tried googling, but without any result.

There are lots of them:

see http://mindprod.com/jgloss/xml.html#VALIDATION

for the source code of one what will verify given the DTD.

For others, including editors and on-line validators see
http://mindprod.com/jgloss/xml.html#SEE
--
Roedy Green Canadian Mind Products
http://mindprod.com

"The telephone is the greatest single enemy of scholarship; for what our intellectual forebears used to inscribe in ink now goes once over a wire into permanent oblivion."
~ Dr. Stephen Jay Gould (born: 1941-09-10 died: 2002-05-02 at age: 60)
 
A

Albert

Tom Anderson a écrit :
Nothing springs to mind.

You could send your output to a validating document builder, and if it
all goes in successfully, you know it's okay. The key code is in here:

http://www.herongyang.com/XML/DTD-Validation-of-XML-with-DTD-Using-DOM.html

However, this would involve building a DOM tree that you didn't need.

DOM is a no go for me, in last resort i could re-parse the output file
(with DTD validation) when the writing is done, but i'd like it to be
done on the fly...

Anyway since it seems to be no lib to do it, i will have to renounce.
 
T

Tom Anderson

Tom Anderson a ?crit :

DOM is a no go for me, in last resort i could re-parse the output file
(with DTD validation) when the writing is done, but i'd like it to be
done on the fly...

Thinking about it, you could do this without actually building a DOM tree.
You use SAX validation, like this:

http://www.ibm.com/developerworks/library/x-tipeh.html

And you need to convert your output stream into an input stream. This is
easily done with a PipedReader/PipedWriter. You then have the parser
running in a separate thread, and have a mechanism for signalling errors
back to the writer (a volatile variable would do it).

It would be easy to do this if you didn't need precise exceptions on the
writer side - exceptions thrown from the call that wrote the offending
text. I think it would be possible to do precise exceptions, but it would
take more attention to detail.

Since you actually need some output from this contraption, you either have
to tee the output stream (easy - and there's a stream in Apache commons-io
to do it) or have the parser re-write what it reads to the final output.

tom
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top