Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post the relevant parts of your XML?
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SAXParserFactory#setNamespaceAware(true)

That was the missing link. Thanks.
- m
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does follow some factory variant pattern, but I can't say which one without looking inside...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic