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 / September 2007

Tip: Looking for answers? Try searching our database.

parsing XML file

Thread view: 
Christine Mayer - 28 Aug 2007 11:00 GMT
Hi,

I've got an XML file, containing key /value pairs. First of all, I
want to validate the XML file by a XSD
Schema file I have. Finally, I want to read all text nodes and put the
key /value pairs into a HashMap.

Questions:
1. Which parser do you recomend?
2. How can I validate the XML file with my XSD Schema?
3. How can I access the text nodes?

Thanks in advance,

Christine Mayer
tony_se - 28 Aug 2007 11:36 GMT
> Hi,
>
[quoted text clipped - 11 lines]
>
> Christine Mayer

Try JDOM
bugbear - 28 Aug 2007 12:38 GMT
>> Hi,
>>
[quoted text clipped - 13 lines]
>
> Try JDOM

JDOM doesn't appear to be a parser

http://www.jdom.org/docs/faq.html#a0360

   BugBear
Arne Vajhøj - 01 Sep 2007 02:57 GMT
>>> I've got an XML file, containing key /value pairs. First of all, I
>>> want to validate the XML file by a XSD
[quoted text clipped - 15 lines]
>
> http://www.jdom.org/docs/faq.html#a0360

It wraps another parser.

But for the end user it does not matter much if the parser is
part of JDOM or external to JDOM.

Arne
steph - 28 Aug 2007 18:36 GMT
> Hi,
>
[quoted text clipped - 7 lines]
> 2. How can I validate the XML file with my XSD Schema?
> 3. How can I access the text nodes?

if you want to "browse" your xml document you need to use a DOM api.
you can find an implementation here http://xerces.apache.org/xerces-j/

the drawback of this method is that you load the whole document in
memory and that the initial parsing is (relativly) slow.

an other option is to parse the document as a stream; known as SAX.
there is a SAX parser (crimson) embedeed in the Sun JRE.

unsing SAX, if you want to validate before loading, you have to parse
twice (ugly!), if not, you can validate and load data at the same time
but your process could fail before the end of the file (maybe unsafe).
I advise you to do it in one pass with a same way to fail using a
temporary Map and not the main one.
<code>mainMap.putAll(tmpMap)</code>
Roedy Green - 28 Aug 2007 23:40 GMT
>I've got an XML file, containing key /value pairs. First of all, I
>want to validate the XML file by a XSD
>Schema file I have. Finally, I want to read all text nodes and put the
>key /value pairs into a HashMap.

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

The Java code to validate with an XSD schema is trivial.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



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.