• 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

namespace in xml

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to parse a xml file. Sometimes, it has namespace, but sometimes not so. Eg,
<a:A>
...
</a:A>
if i use getTagName() in jaxp, i get "a:A". So is there anyway in jaxp that can eliminate all the namespace. and let me just get "A".
Thanks.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try getLocalName()
 
Howie Jiang
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks..
but in DocumentBuilderFactory, we can setNamespaceAware(false), what does this method do? I try it..but when i getTagName(), still return me "a:A"..
 
Howie Jiang
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and same in DocumentBuilderFactory, we can setValidating(boolean), this will validate xml againt what? thanx for reply
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

but in DocumentBuilderFactory, we can setNamespaceAware(false), what does this method do? I try it..but when i getTagName(), still return me "a:A"..


Setting the namespace-aware property indicates a preference to the factory class. I believe the factory is allowed to return a more advanced implementation than requested (i.e. more supported features such as validation, namespaces, etc.) but not the opposite way around. Not sure though.

and same in DocumentBuilderFactory, we can setValidating(boolean), this will validate xml againt what?


If the XML document refers to a DTD and the validation was configured to be "on", the parser validates against the DTD. If the XML document refers to a schema, the factory also needs some other features/properties (as in "SAX features" and "SAX properties") set in order for the parser to validate against the schema.
Take a look at this tutorial at IBM DeveloperWorks for details on validating against schemas (with Xerces).
 
Howie Jiang
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getLocalName() seems cannot.. return me null. i think because we didn't setPrefix for the element, so it doesn't know the prefix is "a" and local name is "A". Am I correct?
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, those are the prefix and local part. I think you should configure your factory to hand out namespace-aware instances to get the getLocalName() working.
 
Howie Jiang
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes.. aftr i setNamespaceAware(true) in factory, then both getLocalName() and getPrefix() works...
thanx very much!!!
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic