File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes XOM generating XML -> schema declaration problem 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 "XOM generating XML -> schema declaration problem" Watch "XOM generating XML -> schema declaration problem" New topic
Author

XOM generating XML -> schema declaration problem

Jan Spengen
Greenhorn

Joined: Nov 28, 2006
Posts: 11
Hello Ranchers.
I have a small but annoying problem, and hope that you can help me out.
I'm working on a programm which reads out xml messages and creates xml messages.
I'm using the XOM package for that. Reading out the XML works fine, validating it is working fine as well. But on creation I got a problem.
The root element of my created XML has to look like that:


The namespace is no problem, I add that in the following way:


But when I want to add the schema-declaration as an attribute:

I get the following error message:

nu.xom.NamespaceConflictException: Attribute prefixes must be declared.
at nu.xom.Attribute._setNamespace(Attribute.java:516)
at nu.xom.Attribute.<init>(Attribute.java:168)
at nu.xom.Attribute.<init>(Attribute.java:70)

But I don't understand it.

I think I declared the prefix in the attribute ? (xsi:noNamespaceSchemaLocation)

Elliott Rusty Harold writes in his tutorial at www.cafeconleche.org
the following:

Attaching a schema is no harder. Just place the necessary xmlns:xsi and xsi:noNamespaceSchemaLocation attributes on the root element.


Didn't I do just that? But it is not working... .

If anyone could shed a light on this I would be really grateful.
I tried the IBM tutorials, the cafeconleche.org tutorials, and various others I found on google, but to no result yet
.
[ November 28, 2006: Message edited by: Jan Spengen ]
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Try using



Rahul Bhattacharjee
LinkedIn - Blog
Jan Spengen
Greenhorn

Joined: Nov 28, 2006
Posts: 11
Thanks for the idea.

But there is no setAttribute method on Element in the XOM API.

Plus I'd expect the same behaviour.
Adding attributes the way I described is also no problem on other Elements in my XML message.
[ November 28, 2006: Message edited by: Jan Spengen ]
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I thought that XOM is JAXP compatible.Sorry no idea about XOM.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I also have no idea about XOM, and the link you posted goes to a site that isn't responding. The JAXP org.w3c.dom classes have both setAttribute and setAttributeNS methods, the latter to be used for namespaced attributes. Maybe XOM is the same except that it does better validation than DOM, which allows you to sneak attributes into the setAttribute method?
Jan Spengen
Greenhorn

Joined: Nov 28, 2006
Posts: 11
Originally posted by Paul Clapham:
I also have no idea about XOM, and the link you posted goes to a site that isn't responding.

Hmm strange, both links are working for me.

Originally posted by Paul Clapham:
The JAXP org.w3c.dom classes have both setAttribute and setAttributeNS methods, the latter to be used for namespaced attributes. Maybe XOM is the same except that it does better validation than DOM, which allows you to sneak attributes into the setAttribute method?

I think I don't understand your question.

Well thanks already for the reply.
I guess I'll have to do some more digging for information.
I thought a moment about switching to JDOM,
but unfortunately that is not really an option.

Edit:
Obviously the problem arises with the "xsi:"
in

If I cut that out and do instead :

Creation runs through to the end without problem. But then I get the problem at validation time as my XML is then not valid against its schema.

Any Ideas why this is causing the error or how to walk around it?
[ November 29, 2006: Message edited by: Jan Spengen ]
Jan Spengen
Greenhorn

Joined: Nov 28, 2006
Posts: 11
It would have been so easy
Like this it works:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XOM generating XML -> schema declaration problem