• 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

text in XML tag

 
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I need something like this

"<element1> some text here
<element2></element2>
</element1>"
(please ignore the double quotes)

The problem is that element1 should be unbounded so I don't specify the type and make element2 its child.
But as element1 is of no particular type, so text can't be added to it.
If I make element1 as string/integer type then I can't add element2 as element1 is of a particular type.

Please advise.

Thanks.

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
XML has no notion of types, so there must be something else in play that you didn't mention. Are you using a library or some other piece of software that restricts what can be added to the XML? Is there maybe an XML Schema that applies? TellTheDetails.
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf,

Thanks for the quick response.

Below is the schema I'm using



This is the xml file for above schema :


This is the error message I get while trying to validate the xml file:-
Text '"

Send comments and suggestions to <url protocol="mailto">barchal@pineapplesoft.com</url>.

"' is not allowed for element <sc:section>. The element declaration's content type is 'element-only.


The xml schema is validated.

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to transport HTML in a validated XML document you need to use CDATA sections to hide the HTML, or escape the special XML characters by using &lt; &gt; etc.
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hI Ulf,

I already had CDATA section but got the same error again.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post the XML that uses CDATA.
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The CDATA use is as follows :-

 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The <![CDATA[ ...code..]]> gets removed after posting.

The start code is this :-

<sc:section>
<![CDATA[<p>Send comments and suggestions to <url protocol="mailto">barchal@pineapplesoft.com</url>.</p>
</sc:section>



and the end code is :-

<p>This means that a document can be rendered differently depending on the media or the audience. For example, a "managerial" style sheet may present a summary view of a document that highlights key elements but a "clerical" style sheet may display more detailed minformation.</p>]]>



The error message is :-

Text '<p>Send comments and suggestions to <url protocol="mailto">barchal@pineapplesoft.com</url>.</p>' is not allowed for element <sc:section>. The element declaration's content type is 'element-only'.

 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried out this one too, but the same error :-

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As long as <p> is in there you'll likely have problems, since that makes it mixed content. Try escaping it using &lt; and &gt;. As it is, the document isn't even well-formed, since the <p> tags have no closing </p> tags.

I'm not an XML Schema expert, though, so there may be better approaches to this.
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf,

I tried out &l t; (ignore the space between l & t) as well as < but got the same error again and again.
I removed "< p>" as you said, but no effect on the error message.

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought it went without saying that you need to treat all other HTML tags (like <url>) the same way.
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't remove the url tag as it is necessary for me to have it.
If I remove it then there is no meaning left for CDATA as well.

Also, even though the p tag doesn't need an end tag, the document is well formed after I test it and the book I'm using for reference does show "</" p>.

Should I keep just one CDATA tag for the entire document or have it for each section tag?
If CDATA ignores the markup tags then what is the use of writing &l t; instead of "<" in CDATA[ ] as both serve the same purpose.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I can't remove the url tag as it is necessary for me to have it.


I didn't say "remove it", I said "escape it". You'd need to un-escape it before you can use the payload as HTML, just like with the <p> tag.

Also, even though the p tag doesn't need an end tag


It does if you use it in an XML document - otherwise the document is not well-formed. Alternatively, you can use "<p/>".

Should I keep just one CDATA tag for the entire document or have it for each section tag?


CDATA is for the payload, not for the actual XML tags. So you'd need them for each section tag.

If CDATA ignores the markup tags then what is the use of writing &l t; instead of "<" in CDATA[ ] as both serve the same purpose.


Yes, only one of these is necessary, not both.
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I didn't say "remove it", I said "escape it". You'd need to un-escape it before you can use the payload as HTML, just like with the
tag.


Yes, only one of these is necessary, not both.



Even If I try with either &l t; or < for the url tag, I get the same error.



Note:-I have used the escape characters instead of<, > in the url tag above.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can get the XML document to validate if I
  • escape "p" and "url" elements
  • add mixed="true" to the complexType declaration
  • add minOccurs="0" to the "element title" declaration

  •  
    pramod talekar
    Ranch Hand
    Posts: 367
    Eclipse IDE Opera Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Ulf,

    I have set the title element's minOccur =0, that's fine and also used escape characters for tags.
    Let me see on Monday what I've used for mixed.

    Thanks for the advice.

    Cheers.

    Gute Nacht.
     
    pramod talekar
    Ranch Hand
    Posts: 367
    Eclipse IDE Opera Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Ulf,

    It's working fine.

    Thanks for the help.

    Could you please tell me what mixed="true" does.

    Cheers.
     
    Ulf Dittmer
    Rancher
    Posts: 43081
    77
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    See the page on mixed content in this XML Schema tutorial: http://www.w3schools.com/schema/default.asp
     
    pramod talekar
    Ranch Hand
    Posts: 367
    Eclipse IDE Opera Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Awesome!
    Thanks a lot.
    reply
      Bookmark Topic Watch Topic
    • New Topic