wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Not quite getting how to allow any html element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Not quite getting how to allow any html element" Watch "Not quite getting how to allow any html element" New topic
Author

Not quite getting how to allow any html element

Thomas Kennedy
Ranch Hand

Joined: Jan 20, 2008
Posts: 137
I want to allow, in addition to any number of my own <link> elements, anything from the html namespace, in any order. I was trying this:



But it will not allow the maxOccurs="unbounded" on line 2. So, I could try this:



Except that I don't want a sequence, I have to allow things in any order. What can I do?


Costs matter. Justice lies in processes not outcomes. Crime is caused by criminals.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 467
    
    2
The use of xs:all is certainly not the right choice. Yes, xs:choice should do at the place replacing xs:all.
Thomas Kennedy
Ranch Hand

Joined: Jan 20, 2008
Posts: 137
Thank you, but I do not quite see how an xs:choice would help here. It allows only one of the listed elements to appear, and I need any number of them, before and after and between my own <link> elements. For example


Can you give an example of what you mean?
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 467
    
    2
Thomas Kennedy
Ranch Hand

Joined: Jan 20, 2008
Posts: 137
Thanks, I'm going to try that! However I am a little skeptical that it will work, because it seems it must be too ambiguous. If I hand the processor something like this:


I don't see how the processor could validate that. Is it one instance of the sequence with one occurrence of each child, or is it two sequences with the first containing only an html element and the second containing only my element? Each of these scenarios is valid, but it seems to me the processor must know which it is dealing with, and it cannot possibly know. So, here goes.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 467
    
    2
Make sure you know the difference between how a thing functions and how it might have been functioning.
Thomas Kennedy
Ranch Hand

Joined: Jan 20, 2008
Posts: 137
Yes, xs:choice worked perfectly. Now I can mix html elements with my own elements.

The other problem, that I was getting html: namespace prefixes and whatnot in the output, I fixed by not using <xs:copy-of> but by re-creating the element instead. So I handle html elements as follows:

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Not quite getting how to allow any html element
 
Similar Threads
SOAP doubt: The Envelope element
[schema] Allow an element to have any content
When the default namespace is an empty string?
XML valiadation using schema
soap fault return empty <detail> element.