• 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

How to declare an attribute of xml element as CDATA type

 
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,

see my code:
<xsd:attribute name="password" type="xsd:CDATA"/>
the jdeveloper complain the "reference xsd:CDATA not found", could you help? how to declare a CDATA attribute in the xml schema?
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no datatype called xsd:CDATA. A CDATA section is a means to escape the String from parsing.

If you need more info about the available datatypes look here: XML Schema Built-In Datatypes

You should declare the field as xsd:string. If you are using a reasonable xml serializer it will automatically escape the characters if there is a need to do so. If you serialize your xml document yourself you just have to embed the password in a CDATA section.

Anyway you have to make sure the password does not contain ]]>.
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for helps, but i could not embed "<!CDATA[[.....]]" in the attribute, the "><" in attribute is not allowed, i think it should be legal to use the "<!CDATA[[.....]]" in the element value. is that correct? can you use it in the attribute? let me know
>
 
Xin Zoo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, i overlooked this. But still i think you should declare the attribute as xsd:string and let the xml serializer do the escaping. I think the serializer will escape a " and a & with a character reference. I believe these are the only harmful characters in an attribute. Try it and tell us if it works. Again, if you do the serializing yourself then replace any occurence of " by &quot; a & by &amp; and revert the operation when you deserialize the document. And please report if it worked out.
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In fact, i am designing a xml configuration file for a java application, which handle the database operation, so i need to put the password somewhere in the config file. to xml structure point of view, it is better to define the password as an attribute, but it is possible the "<" is included in the password string, and i could not find a good way to handle this case, because the "<" is not allowed in the attribute, i am not sure if the serializer you mentioned and handle it well.
so if i could not find the good way, i have to put the password as an element in the file, then wrap it by "<![CDATA[....]>", that maybe works, but the file structure looks awful.
 
Xin Zoo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you not escape the character? Try to escape it like this: &lt;
 
this is supposed to be a surprise, but it smells like a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic