• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Beginner In XML! Need Help

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am beginer in XML and I am confused with such a huge documentation on XML.

For the project I am working on, we thought of using an xml file for application configuration and get the configuration values as and when required by the application. I thought I would parse my xml file and keep that in memory by running a servlet on server startup. Servlet would call my parser program. I guess I should go for DOM parser.

In this scenario, I am confused if I have to use SAX parser or DOM parser. Using these parsers will I be able to get the value of the configuration paramter from the XML document given name of the configuration parameter as input? (In my case it would be tag name)

Sample program would be a great help to me.

When I write a dtd for my xml file and try to validate it I am getting SAXException. I am using Jbuilder validator to validate my XML file. I guess by default it uses SZX parser to validate.

Here are the DTD and XML files.
-------------
<!ELEMENT application-security ( application-account-code, database-environment-code, environment-description, chances-before-revoked ) >

<!ELEMENT application-account-code ( #PCDATA ) #REQUIRED>

<!ELEMENT chances-before-revoked ( #PCDATA ) #REQUIRED>

<!ELEMENT database-environment-code ( #PCDATA ) #REQUIRED>

<!ELEMENT environment-description ( #PCDATA ) #IMPLIED>

-------------
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE application-security SYSTEM "AppSecurity.dtd">

<application-security>
<application-account-code>FA</application-account-code>
<database-environment-code>P1</database-environment-code>
<environment-description>Production</environment-description>
<chances-before-revoked>3</chances-before-revoked>
</application-security>
-------------

If anyone could tell me what went wrong and How I should proceed futher would be a great help to me.

early replys are greatly appreciated.

Thank you very much inadvance
Saritha
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Saritha ventrapragada:
In this scenario, I am confused if I have to use SAX parser or DOM parser. Using these parsers will I be able to get the value of the configuration paramter from the XML document given name of the configuration parameter as input? (In my case it would be tag name)

I would suggest using the DOM API. It's a lot easier than writing your own SAX handler.

Originally posted by Saritha ventrapragada:
Sample program would be a great help to me.


The Java Developer's Almanac has plenty of DOM code examples.
reply
    Bookmark Topic Watch Topic
  • New Topic