Hi, I need to parse an xml file. I am parsing it using dom. The problem i am facing is : When there are some optional fields which means that the xml file may or may not contain them my parser should not read them. So how do i stop my parser to reading the optional fields.
A DOM parser is going to read and parse the whole document - you can't pick and choose. It is up to your subsequent code to handle only the elements you want. Why is this a problem? Bill
Joined: Aug 26, 2003
Firstly sorry to say that the parser i am using is Sax....The problem is that i shud read information from the xml and store it in the db. when i say a field is optional user can have or not have that tag in the xml.So if i am reading by tag i am getting the exceptions. Firstly is the approach of using sax and reading xml is ok or plz let me know the right way
I am not sure if u r using a schema to validate the xml file. If so make the element an optional one so that u may not get an exception while parsing. Something like this : <xs: element name="abc" type="xs: string" minOccurs="0" /> This may help!
Joined: Jan 23, 2002
Hello Vaidya, I'll have to ask you as well to edit your display name a bit so that it complies with our naming policy. Thanks, and welcome to the JavaRanch!