This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

XmlBean validation

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
  • 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: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
  • 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: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a reasonable workaround to me!
 
nandini lagunia
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you think so???

Well thanks for your prompt reply and help.
 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
ice is for people that are not already cool. Chill with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!