File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get XML file name ?

 
Gurpreet Saini
Ranch Hand
Posts: 295
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Paul Clapham
Sheriff
Pie
Posts: 20177
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic