• 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

simple SAX parsing questions

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
New to SAX parsing.

1) Does SAX parser parse the XML file exactly following the syntax, i.e. by the order of the xml file's syntax strictly ?
If a user makes a mistake that he is supposed to put a data value between a tag but he accidentally put another tag name there, will the SAX parser still parse the tag instead of the "expected" value field ?

2) if I have a xml tag looks like

<dept>
Chemical Enginnering
<head> Dr. Kidds </head>
</dept>

for the characters(char[] ch, int, int) method, if I just print out the the contents, then when it encounters "<dept>" tag will it print

"Chemical Enginnering
<head> Dr. Kidds </head>"

or "Chemical Enginnering" , or anything else ?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1) Does SAX parser parse the XML file exactly following the syntax, i.e. by the order of the xml file's syntax strictly ?
If a user makes a mistake that he is supposed to put a data value between a tag but he accidentally put another tag name there, will the SAX parser still parse the tag instead of the "expected" value field ?


SAX parsers just read a single pass through the characters - if there is a tag start you WILL get a call to startElement().

2) if I have a xml tag looks like

<dept>
Chemical Enginnering
<head> Dr. Kidds </head>
</dept>


1) The characters method will get "
Chemical Engineering
"
(not necessarily in a single call, there may be multiple calls to characters()
2) The startElement method will get the <head> information
3) The characters method will get " Dr Kidds "
etc.

Why would you expect anything else?
Bill
 
My name is Inigo Montoya, you killed my father, prepare to read a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic