• 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

XmlBean validation

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using XmlBean. I've compiled my schema and generated classes and interfaces which I am using
comfortably in my application. Problem is that I had created the schema using namespace but the xml
which I am getting doesn't have any namespace. So everytime when I try to validate
the xml ,it returns false.

Is there any way in which I can tell it to ignore the namespace and then validate?
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

Can you show us the code you are using to validate at the moment?
 
nandini lagunia
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here it goes...


XYZDocument xyzDoc = XYZDocument .Factory.parse(xmlString); //xmlString is an xml in String format.
boolean flag=xyzDoc.validate();

Since I'd used namespace while creating xsd and the xml which I am getting doesn't have any namespace
specified in it,I am getting the value of falg=false.

Compiler says org.apache.xmlbeans.XmlException: error: The document is not a XYZ@http://www.abc.com/sud/xyz: document element namespace mismatch expected "http://www.abc.com/sud/xyz" got ""
 
Martijn Verburg
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, some Java/XML APIs allow you to switch the namespace validation off. Have you check the API docs for XYZDocument? In other APIS I've seen things like document.setNamespaceAware(false);
 
nandini lagunia
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
XYZDocument is the class which is generated when I compile the schema using scomp command.
I don't see setNamespaceAware(flag) method which could be invoked on it.
There're some methods associated palying with namespace in XmlOption class which I can use
but don't know how.

I can insert namespace in the xmlString programatically but that would be the crude way of
doing things.

 
Martijn Verburg
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, if there's no way in the API to ignore that then the crude option might be the way to go
 
nandini lagunia
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
lol...

well I've inserted the namespace crudely in the xml string but I am afraid to show it to my system analyst.
He sure gonna not like it.
 
nandini lagunia
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know how I did it but I think I pulled it off. Here goes the solution...

XmlOption xmlOption=new XmlOption();
Map<String,String> map=new HashMap<String,String>();
map.put("","http://www.abc.com/sud/xyz"); //"http://www.abc.com/sud/xyz" is the namespace that i was using
xmlOption.setLoadSubstituteNamespaces(map);
XYZDocument xyzDoc = XYZDocument .Factory.parse(xmlString,xmlOption);

Now it doesn't complain that namespace not found in xml file.
 
Martijn Verburg
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like a reasonable workaround to me!
 
nandini lagunia
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you think so???

Well thanks for your prompt reply and help.
 
Martijn Verburg
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic