473,757 Members | 10,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Storing HTML in an XML file and rendering it in the browser...

So I am quite upset that after working for a few hours on getting an
XML file format and XSL file that formats the XML data appropriatly,
only to find that if you store HTML code in your XML file (even in a
CDATA block), after the XML file is rendered, the HTML that was stored
in the XML file is not rendered, essentially put into the page as if it
had <pre> tags around it.

I know that someone is going to yell at me and say that the XML file
should only contain the content of the page, and that the formatting
should be done by the XSL, but I have a particluar use case for this.
Essentially I store HTML in my database, and want it to be transmitted
to the browser and rendered on the fly. As brief as I can say it is
like this:

I plan on using Javascript to download small XML files from my server
and place their contents, formatted accordingly, onto a page. The trick
here is that my XML file is basically a serialized dataset.
Additionally, I store HTML in my database for some fields. I want to
use XSL because I don't really care about the data in the XML file, I
just want it displayed (which is a perfect application for XML/XSL). I
have read that I could do something cheesy like matching the
A|P|BR|FONT tags, but that seems REALLY cheesy. Here is a bare bones of
my XML file:

<Data>
<RowDefinitio n>
<Field name=foo displaytype"Tex t|HTML|Dollars| Link|Image" />
... etc ...
</RowDefinition>
<Rows>
<Row>
<Value name=foo><![CDATA[A Value or maybe some HTML
code]]></Value>
... etc ...
</Row>
... There may or may not be more than one Row tag ...
</Rows>
</Data>

(I just typed this so it may not really be well formed BTW)

Is there something besides CDATA that I could use in this case? I can't
seem to find much usefull information on such a topic.

I have tried encoding the chars first, IE &lt; and &gt; , both with and
without the CDATA declerations, and I do get something different. With
the CDATA declaration, the &gt; comes through as is, but without the
CDATA declaration, &gt; comes through as >. I was really hopin that
something like this would work, damn...

My other (and more dreaded option) is to use a javascript XMLDom and
parse the contents out manually and set certain parts of a
spans.InnerHTML property to the value from the DOM, but I really don't
want to have to write recursive javascript functions, and design HTML
that responds that well to this type of thing. I guess I would have had
a hard time getting the XSL to render the XML via javascript, so
writing some XMLDom javascript code may be my only option...

Any ideas on this, or maybe if you don't think that this is possible,
if someone could send me a good, browser concious, reference guide to
the various Javascript XML Doms out there, it would be greatly
appreciated...

Thanks for your time in advance!

Andy Baldwin

Nov 12 '05 #1
7 9279


An************@ gmail.com wrote:
I plan on using Javascript to download small XML files from my server
and place their contents, formatted accordingly, onto a page. The trick
here is that my XML file is basically a serialized dataset.
Additionally, I store HTML in my database for some fields. I want to
use XSL because I don't really care about the data in the XML file, I
just want it displayed (which is a perfect application for XML/XSL).


While XSLT is a nice tool to transform XML it is not designed to process
HTML unless you can ensure that your HTML is XHTML or is transformed to
XHTML before the XSLT processor sees it.
So while you can choose to store some HTML tag soup in a CDATA section
of an XML document you have to live with the consequences, any XML
application (like XSLT) sees the stuff in the CDATA section as plain
text and not as structured markup.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
> While XSLT is a nice tool to transform XML it is not designed to process
HTML unless you can ensure that your HTML is XHTML or is transformed to
XHTML before the XSLT processor sees it.
So while you can choose to store some HTML tag soup in a CDATA section
of an XML document you have to live with the consequences, any XML
application (like XSLT) sees the stuff in the CDATA section as plain
text and not as structured markup.


I love your phrase "HTML tag soup", classic...

I agree, I DON'T want it to process the underlying HTML, however I want
it to ultimitly be "rendered" in the browser with the bold, LI and
other tags rendered into the appropriate text decorations.

After thinking about it some more overnight, I realized that this may
be a moot point. Considering how I am applying the translation to my
XML file, I have not actually run the code through an XML Dom to do the
translation and save the resulting HTML to a file. Instead I
shortcutted it and placed the following tag at the top of the XML file,
so when it is opened in a browser the transformation is done inline,
and the resulting HTML is never actually saved and rendered.

( IE <?xml-stylesheet type='text/xsl' href='DataSet.x sl'?> )

I think that programatically getting the HTML that results from this
translation, then either saving it to an actual HTML file, or using
javascript to set a span's innerHTML property to the resulting
translated HTML code would actually work. I just hadn't gotten that
far, but this may be a "non-issue" after all (at least I hope :D)

Andy Baldwin

Nov 12 '05 #3
Hello!
<Data> .... <Rows>
<Row>
<Value name=foo><![CDATA[A Value or maybe some HTML
code]]></Value>
... etc ...
</Row>
... There may or may not be more than one Row tag ...
</Rows>
</Data>


Just use

<xslt:value-of
disable-output-escaping="yes"
select="/Data/Rows/Row[1]/Value[@name = 'foo']/text()"
/>

This will copy the plain text from the CDATA to the output, but I don't
know if it works with not well formed HTML.

But there should be no reason to create Tag Soups these days!
--
Pascal Schmitt
Nov 12 '05 #4
Pascal Schmitt wrote:
Hello! ....
....
....
Just use

<xslt:value-of
disable-output-escaping="yes"
select="/Data/Rows/Row[1]/Value[@name = 'foo']/text()"
/>

This will copy the plain text from the CDATA to the output, but I don't
know if it works with not well formed HTML.

But there should be no reason to create Tag Soups these days!

Cool, I will try it out, thanks for the tip!

Just curious, how else could I handle this situation? I mean, I am
basically trying to use AJAX to get data from the DB sent to the client
in an XML file. The data in the DB could contain raw HTML, so there
really isn't much other choice that I have, right? The only other way
is to parse the XML and then pulling out the data individually, I could
stick the values into appropriate span tags on the page. However, it
would seem to be much easier to just XSL it and use that result.

Any other suggestions would be greatly appreciated! :D

AB

Nov 12 '05 #5
Ohh yeah, and disable-output-escaping="yes" worked like a champ!

But yeah, it seems that I have to create "tag soup" I can't think of
any other way unfortunatly...

Thanks for the help!

AB

Nov 12 '05 #6


An************@ gmail.com wrote:
and disable-output-escaping="yes" worked like a champ!


But be aware that disable-output-escaping is an optional feature that an
XSLT processor does not need to implement at all or might not support in
certain scenarios (like not serializing the result tree).
It can help you if you know you use a certain processor and output
format where it is supported but if you want to write XSLT stylesheets
that rely on disable-output-escaping and you want to throw them at
various processors in the wild you will face problems. For instance the
XSLT processor in Mozilla/Firefox does not support
disable-output-escaping thus if you want to use that feature in
client-side XSLT Mozilla is out.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #7

Martin Honnen wrote:
But be aware that disable-output-escaping is an optional feature that an
XSLT processor does not need to implement at all or might not support in
certain scenarios (like not serializing the result tree).
It can help you if you know you use a certain processor and output
format where it is supported but if you want to write XSLT stylesheets
that rely on disable-output-escaping and you want to throw them at
various processors in the wild you will face problems. For instance the
XSLT processor in Mozilla/Firefox does not support
disable-output-escaping thus if you want to use that feature in
client-side XSLT Mozilla is out.

Yes, I figured that would be problematic, I have given up on the XSL
transform and just started researching how to use the various XMLDoms
that Firefox and IE have available, seems that if GMAIL uses them for
AJAX types of things, then it must be possible in both of those
browsers...

AB

Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

71
6504
by: tomy_baseo | last post by:
I'm new to HTML and want to learn the basics by learning to code by hand (with the assistance of an HTML editor to eliminate repetitive tasks). Can anyone recommend a good, basic HTML editor that's a step beyond Notepad (not a WYSIWYG tool). Thanks.
72
5440
by: Mel | last post by:
Are we going backwards ? (please excuse my spelling...) In my opinion an absolute YES ! Take a look at what we are doing ! we create TAGS, things like <H1> etc. and although there are tools (dreamweaver and the like), they are all at the lowest level of programming (something like assembly as oposed to C++ etc.). These tools create "brain-dead" developers that constantly have to plough through tons of tags to do the simplest thing. ...
81
5176
by: sinister | last post by:
I wanted to spiff up my overly spartan homepage, and started using some CSS templates I found on a couple of weblogs. It looks fine in my browser (IE 6.0), but it doesn't print right. I tested the blogs, and one definitely didn't print right. Surveying the web, my impression is that CSS is very unreliable, because even updated browsers fail to implement the standards correctly. So should one just avoid CSS? Or is it OK if used...
6
3048
by: bissatch | last post by:
Hi, I am currently writing a news admin system. I would like to add the ability to add images to each article. What I have always done in the past is uploaded (using a form) the image to a folder on the server and then in the database table that I INSERT the news article, I'll store the path of the uploaded image. To me this seems a bad idea as if the image paths were changed on the
3
1728
by: Clay Black | last post by:
I need to find a way to save an HTML page to the IIS server. What I need is to have a button that once it is clicked the current page being displayed is saved to a location on the local IIS server. I know there are ways to go and get a page, but this one would be dynamic and wouldn't be saved so I would need to save it while it is still active or have it forwarded to an asp.net page that will take the html code and save it to a file. TIA...
10
1535
by: George | last post by:
Hi, I have a report which shows all records from database into the browser. The final HTML comes out about 5 Meg. It takes 1 minute 5 seconds for transfer to show up when i hit the page with IE The trace info shows that output was done within 1 second and then i guess it took so much time (> 1 minute) for it to actually be transferred to IE. I am doing test on the same machine. IIS and IE are on the same machine and I believe the actual...
32
2713
by: Next | last post by:
Hi folks, Years ago, it occurred to me that a lot of the trouble of writing web browsers is caused by the upside-down arrangement of things: Javascript code exists inside a document, when really it should be the other way around. And yet, although this seems fairly obvious to me, having tried myself to write a web browser and given up, I don't see a lot of movement by major web browser projects in a direction that might TRULY fix the...
2
1781
by: Giedrius | last post by:
hi, i have an idea to make admin tool on home computer, that would generate html files using some kind of templates and database data and put these generated html files to public web server, witch doesn't have running asp.net, using ftp access. why i need so? because: 1) my project doesn't need to receive any data from browsing customers, it will be only company news, info about new products - so it's enough to have static html on...
8
3353
by: rn5a | last post by:
I have a HTML page named Index.html which is divided into 3 frames. The URL of 2 of the frames are HTML pages but the 3rd frame houses a ASP page. Now when I go to Windows Explorer, navigate to the folder in which the all the 4 files (3 HTML + 1 ASP) reside & select Index.html (by clicking with the mouse or by using the arrow keys on the keyboard), strangely the Windows "File Download" dialog box (with 'Open', 'Save', 'Cancel', 'More...
0
9298
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9737
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.