• 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

How to get XML file name ?

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

I have xml file please tell me the code to get the name of XML file name using SAX parser. Secondly, How can I get the attributes of xml file using SAX parser without hardcoding them.

thanks in advance,

gurpreet
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gurpreet Saini:
I have xml file please tell me the code to get the name of XML file name using SAX parser.

You can't. First of all, the SAX parser doesn't have to be parsing data from a file. Or even from a URL. It could be parsing data from a String variable. And second, the parser doesn't know what it's parsing until you call its parse() method.

How can I get the attributes of xml file using SAX parser without hardcoding them.

When the parser calls your startElement() method, the fourth parameter is a reference to an Attributes object. That's where you get the attributes from. You don't need to hard-code anything.
 
Gurpreet Saini
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

Thank you very much for your response. The thing is I would be getting lets say 10 xml files from client one after the other in the form of String variable. So, I want my SAX parser be so generic that it can parse the incoming String which is nothing but the contents of xml file. So, how do I proceed with parsing ?. Is there way out without hardcoding the elements or tags . How shall I know which String (which xml file in String is coming) ?.

thank you

gurpreet
 
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
I suggest you spend some time with basic XML tutorials. Fortunately, Harold's excellent book is available on line. After you work through some simpler examples of SAX parsing your questions should be answered.

Right now you appear to be trying to tackle the whole problem at once, work step by step.

Bill
 
reply
    Bookmark Topic Watch Topic
  • New Topic