• 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

XML with HTML

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Can we include HTML tags in XML.What happens if we do so.can anybody tell me this.
Thanx in advance
Preethi
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use HTML tags in XML on the condition that they are properly formatted as XML and part of the DTD (if you use one).
This means that all tags must be properly closed, all parameters must have values and those values must be enclosed in quotes. While all this is required in HTML, many people forget because most browsers are kinda forgiving.
Your XML validation will not check against the HTML DTD, so the code need not be valid HTML (td can exist outside a tr for example).
 
Preethi Suryam
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeroen Wenting!
Thanx a lot for ur reply,but i have one more doubt.can we combine both the HTML and XML,for example in JSP the html part is written along with the servlet.hope u got me what i meant.could u pls help me out with a small example to support ur answer.
Regards
Preethi
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the context of the question? Without more context it is very difficult to become more specific than Jeroen already was.
If you want to include HTML in your XML, sure, that's possible, just go ahead and do it.
But, if your output needs to be processed by an XML parser, it will have to be well-formed XML and things get stickier. Valid HTML is not valid XML. Sometimes the parser has some HTML leniency features built in (e.g. XSL processors). Or maybe you can use xhtml, which is essentially an XML-ified HTML. Or you could escape the HTML markup (> and < ) so that the HTML is just plain text, not XML.
If your output is processed by an XML parser, that is. You don't say.
Furthermore, if it's processed by a validating XML parser, it needs to be valid XML. If you cannot escape your HTML markup you will have to use XML namespaces, since your (x)HTML and your XML probably come from different vocabularies.
Again, you don't really see if it needs to conform to any XML DTD.
For information on all of the above, by the way, see http://www.w3c.org.
Now this answer may not mean a lot to you, or be very useful. If you could be more specific about your needs, it might be possible to help you better?
Success!
 
Preethi Suryam
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter!
My question is,for example lets take a small example......
<?xml version="1.0"?>
<!DOCTYPE pizza[
<!--comments are given like this -->
<!ELEMENT pizza (topping,price,size)>
<!ELEMENT topping (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ELEMENT size (#PCDATA)>
<!ELEMENT a (href)>
<!ATTLIST topping extracheese (yes|no) "no">
]>
<html>
<body bgcolor=blue>
<pizza>
<topping extracheese="yes">Pepproni</topping>
<price>60.00</price>
<size>large</size>
</pizza>
</body>
</html>
we r not getting the body color as "blue" in the output.should we declare even the body and html tags in the DOD.i am not able to exactly put out my problem clearly.hope u got me.pls help.
Thanx a lot
Preethi
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Preethi !!
ive the same problem as yours, if we include extra HTML tags in the XMl file, the browser does not parse them and displays them as it is.
eg:
suppose we add the <B> tag in yr code as...
<size> <b> large </b> </size>
then the browser will display the <b></b> tag in the output.
Ive also posted my problem and the link is.. http://www.javaranch.com/ubb/Forum31/HTML/000162.html

Some people have suggested me o include the tags in the XSL file but that is fine. The problem is : if we put tham in xml file without defining them in the DTD.
I hope ive understood yr problem.
Thanks & Regards
Neeraj Singhal
 
Preethi Suryam
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Neeraj!
U got me!!! What i got is the same output.The HTML tags are being displayed as they are.I shall try it in XSL.Thanx a lot for ur reply.
Have a Nice Day!
Preethi
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

can be turned into a HTML table using the following stylesheet:

Note the use of XML namespaces (the xmlns: bit) to define a namespace (xsl for the stylesheet tags, thereby separating them from the HTML tags.
It may not be too difficult to adapt this to your situation.
Hope this helps.
Peter
[This message has been edited by Peter den Haan (edited December 15, 2000).]
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this one:
change
<body color=blue>
to
<body color=blue>
do the same thing for </body>
That may work
 
Preethi Suryam
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Peter your code has helped me a lot.I thank even Cynthia for ur response.
Have a Nice Day!
Preethi
reply
    Bookmark Topic Watch Topic
  • New Topic