aspose file tools*
The moose likes XML and Related Technologies and the fly likes Namespace in SAX........... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Namespace in SAX..........." Watch "Namespace in SAX..........." New topic
Author

Namespace in SAX...........

Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Acc to the documentation on the startElement,

Any or all of these may be provided, depending on the values of the http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixes properties:

What I am trying to understand is the values of localName, qName and namespaceURI. My examples give me null values for namespaceURI and
localName. Although, I have a fully qualified name and a xmlns attribute
on the root element, I don't see them on the various elements.
Anyone has an good XML file that will show me the differences.
Also, what does it mean to (un)set the values mentioned in the above quote...
Thanks for your help.
- m
[ March 02, 2004: Message edited by: Madhav Lakkapragada ]
[ March 03, 2004: Message edited by: Lasse Koskela ]
[ March 03, 2004: Message edited by: Lasse Koskela ]

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Could you post the relevant parts of your XML?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Here goes............
XML File -

I took the sample code and modified the foll. code -

Output looks like -


- m
[ March 03, 2004: Message edited by: Madhav Lakkapragada ]
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
For the output I am expecting -

What am I missing ?
BTW, I am using J2SDK 1.4.2_03-b02

E:\temp\tutorials\sax>java -version
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

- m
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Did you do SAXParserFactory#setNamespaceAware(true) when you obtained the SAXParser instance? If you didn't, then that's why the parser interprets the "foo:bar" as the element's name.
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
SAXParserFactory#setNamespaceAware(true)

That was the missing link. Thanks.
- m
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Ok, now that my initial excitement has worn down...
kinda have a design question.....
IMO, it is enough to have to make the parser
namespace aware, right?
So, why should I make the whole factory aware
of the namespace. If the factory is made aware
of the namespace, any (read all) parser created from
that factory are being forced to be namespace aware
(or not). Doesn't this beat the factory template.
If you are wondering why I need more than one parsers,
trust me, there are valid use cases why I need
them, afterall its not a singleton pattern, or is it ?.
Anyone out there have thoughts about this...
- m
I suffer from extreme curiosity, insomnia and a
tendency to question everything.........
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
The trick is that once you have a parser implementation, it's a bit difficult to make it namespace-aware with a setter method unless the parser actually is namespace-aware (but simply ignoring namespaces).
It may be that most parser implementations use a "configuration" approach (i.e. are namespace-aware but don't act like that), but the factory class should be given an option to select two different implementations if that's what the developers have preferred.
Creating a couple of differently configured instances of SAXParserFactory shouldn't be a problem in any case...
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Creating a couple of differently configured instances of SAXParserFactory shouldn't be a problem in any case...

I don't debate the creating for more factory objects, what I am
interested in knowing is the design principles - factory verses
singleton.
Does the SAXParserFactory follow a factory pattern ?
From the Class definition it wasn't clear to me.
But they do make a point that creating more than
one factories is 'acceptable'. Anyways.....
- m
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
It does follow some factory variant pattern, but I can't say which one without looking inside...
 
jQuery in Action, 2nd edition
 
subject: Namespace in SAX...........