Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

XML Validation

Thread view: 
timothy.williams@comverse.com - 11 Jan 2006 19:40 GMT
Never done this....fairly new as well.

I am storing XML files on a server.  Before I write the file to the
disk, I would like
to verify the syntax is correct.  I don't want to validate it because I
don't have
any schema or data definition document to validate it against.

I just want to know the file is valid XML syntax.

How can I go about this?

thanks in advance.

TRW
Steve W. Jackson - 11 Jan 2006 21:10 GMT
> Never done this....fairly new as well.
>
[quoted text clipped - 10 lines]
>
> TRW

Given the description, I take "valid syntax" to mean that it's
well-formed XML.  If so, why not simply attempt to parse it?  If it
parses without error, it should be well-formed.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama

TRW - 12 Jan 2006 19:19 GMT
Thanks Steve.

Yes, I agree with that.

Is there a way to parse the document without having a definition
document
or schema?

Basically, just check pure syntax not to see if the tags are valid.
Steve W. Jackson - 12 Jan 2006 20:32 GMT
> Thanks Steve.
>
[quoted text clipped - 4 lines]
>
> Basically, just check pure syntax not to see if the tags are valid.

Assuming you want to use the XML facilities built into Java, it's as
easy as pie.  You'll need to call DocumentBuilderFactory.newInstance()
to get a new DocumentBuilderFactory, then configure factory (see the API
in javax.xml.parsers).  Call the factory's newDocumentBuilder() method
to create a DocumentBuilder, and the call the builder's parse() method.  
There are multiple parse methods, allowing you to parse a file,
InputStream or InputSource.  One of those also makes it possible to
parse a string rather than reading a file.  And no validation against
any DTD or schema will be attempted when the factory is configured that
way.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama

James Westby - 12 Jan 2006 22:03 GMT
> Thanks Steve.
>
[quoted text clipped - 5 lines]
>
> Basically, just check pure syntax not to see if the tags are valid.

How about

http://www.perfectxml.com/JAXP.asp

Or there are many XML tutorial available on the web, you just need to
find one that shows how to using your chosen technologies.

The tutorial above uses DOM and JAXP, but there are other parsers
available. You could also use SAX if you are worried about memory. There
is the option to implement something yourself if you are really
concerned with speed and simplicity and just want to check e.g. that
every opening tag has a closing tag, this would be pretty easy. However
if you decided you wanted to do a little more later on it would be
benificial to be using something with more functionality.

James


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.