This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
"<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.
Thanks,
Pramod
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
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.
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
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
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 < > etc.
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'.
As long as <p> is in there you'll likely have problems, since that makes it mixed content. Try escaping it using < and >. 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.
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
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
I thought it went without saying that you need to treat all other HTML tags (like <url>) the same way.
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
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
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.