It's not a secret anymore!*
The moose likes XML and Related Technologies and the fly likes How to get XML file name ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to get XML file name ?" Watch "How to get XML file name ?" New topic
Author

How to get XML file name ?

Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
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
Bartender

Joined: Oct 14, 2005
Posts: 18710
    
    8

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

Joined: Jun 09, 2002
Posts: 295
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

Joined: Mar 22, 2000
Posts: 12809
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get XML file name ?