473,698 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML, CSS and JavaScript

I'm trying to apply CSS to an XML file and interject a JavaScript
function into the page. I have the following source code:

foo.xml
======
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="foo.css" type="text/css"?>

<doc>
<element1>
my text
</element1>
</doc>
foo.css
======
element1 {
display: block;
height: 100px;
border: 1px solid Black;
This works great for me when I load that page in IE and Firefox. Now, I
want to add a JavaScript file into the mix.

foo.js
=====
alert( "Hello, World from foo.js");
When I try to include it into the XML as a <scripttag, I don't get
the desired behavior. I've seen suggestions where people are using XSLT
to transform the XML into HTML, but I'd prefer to leave HTML and all
it's legacy behind. Is this possible?

Jul 19 '06 #1
6 1359


Dan H wrote:

When I try to include it into the XML as a <scripttag, I don't get
the desired behavior. I've seen suggestions where people are using XSLT
to transform the XML into HTML, but I'd prefer to leave HTML and all
it's legacy behind. Is this possible?
If you want to go esoteric to build pages that work with some latest
releases of some browser then you can use the XHTML script element in
XML e.g.
<script xmlns="http://www.w3.org/1999/xhtml" type="text/javascript"
src="foo.js"></script>
Mozilla and Opera should support that only you need to learn to script
the XML DOM then (no document.write) and live with browser flaws like
Mozilla not incrementally parsing and rendering XML so expecting script
to do anything while the document is parsed can be a pain.
And IE knowns nothing about elements in the XHTML namespace, it will not
understand that script element as having any particular semantics.

So go ahead, leave that "legacy HTML" behind you, and lots of potential
visitors too.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 19 '06 #2
Someone's a little grumpy. Instead of writing responses maybe you
should try a nap. Or maybe it's that "warm" German personality you
have.

While some seek to look at the practical applications for everything,
some of us experiment with the "esoteric" to see what it's capable of.

Martin Honnen wrote:
Dan H wrote:

When I try to include it into the XML as a <scripttag, I don't get
the desired behavior. I've seen suggestions where people are using XSLT
to transform the XML into HTML, but I'd prefer to leave HTML and all
it's legacy behind. Is this possible?

If you want to go esoteric to build pages that work with some latest
releases of some browser then you can use the XHTML script element in
XML e.g.
<script xmlns="http://www.w3.org/1999/xhtml" type="text/javascript"
src="foo.js"></script>
Mozilla and Opera should support that only you need to learn to script
the XML DOM then (no document.write) and live with browser flaws like
Mozilla not incrementally parsing and rendering XML so expecting script
to do anything while the document is parsed can be a pain.
And IE knowns nothing about elements in the XHTML namespace, it will not
understand that script element as having any particular semantics.

So go ahead, leave that "legacy HTML" behind you, and lots of potential
visitors too.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 19 '06 #3
Dan H said the following on 7/19/2006 3:53 PM:
Someone's a little grumpy. Instead of writing responses maybe you
should try a nap. Or maybe it's that "warm" German personality you
have.
Or maybe it's your ignorance of a good answer that eludes you.
While some seek to look at the practical applications for everything,
some of us experiment with the "esoteric" to see what it's capable of.
Then experiment. But say so to begin with and you will see a difference
in the response. The basic assumption in this group is that it is for
the WWW and the responses will be based on that unless you say differently.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 19 '06 #4

Randy Webb wrote:
Dan H said the following on 7/19/2006 3:53 PM:
Someone's a little grumpy. Instead of writing responses maybe you
should try a nap. Or maybe it's that "warm" German personality you
have.

Or maybe it's your ignorance of a good answer that eludes you.
While part of the message was good (i.e. <script
xmlns="http://www.w3.org/1999/xhtml" type="text/javascript"
src="foo.js"></script) there's no reason to flame someone asking a
legit question in a newsgroup. It's not as if I was asking a common
question.
While some seek to look at the practical applications for everything,
some of us experiment with the "esoteric" to see what it's capable of.

Then experiment. But say so to begin with and you will see a difference
in the response. The basic assumption in this group is that it is for
the WWW and the responses will be based on that unless you say differently.
So what. He could have said it would be a hit or miss proposition with
different browsers without such inflammatory language. Do all
non-production issues get shot down with such force or is the point to
banish the non JavaScript experts?

Jul 19 '06 #5


Dan H wrote:

While some seek to look at the practical applications for everything,
some of us experiment with the "esoteric" to see what it's capable of.
Go ahead and experiment, but if the aim is not experimenting but rather
leaving "legacy HTML" behind then I think you will find that HTML is not
legacy and HTML and CSS and JavaScript has much better support and
implementation than XML and CSS and JavaScript.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '06 #6
VK

Dan H wrote:
I'm trying to apply CSS to an XML file and interject a JavaScript
function into the page.

It is not possible.
XML is /data source/. It is not a viewable document: it is a source to
generate viewable document. You can generate HTML out of it, XHTML,
Excel sheet etc. etc. But you cannot handle the presentational
attributes of a data source as you cannot talk about "of what color
bytes are" :-)

Note: All modern browsers have XML Viewer in them to look at XML data
with more comfort. But it is not about "document presentation" or
styling or scripting of any kind of course.

I have the following source code:

foo.xml
======
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="foo.css" type="text/css"?>

<doc>
<element1>
my text
</element1>
</doc>
foo.css
======
element1 {
display: block;
height: 100px;
border: 1px solid Black;

You would be highly surprised of what kind of document really is
generated inside your browser :-). A hint: nothing about XML. The rest
depends on Content-Type you are using for foo.xml
When I try to include it into the XML as a <scripttag, I don't get
the desired behavior. I've seen suggestions where people are using XSLT
to transform the XML into HTML, but I'd prefer to leave HTML and all
it's legacy behind. Is this possible?
No, it is not possible. But you can have the resulting document out of
your XML data in XHTML format - if it makes you feel more advanced. But
I would stay with HTML: "tag soup", "legacy trash" etc. is in the
heads, not in HTML itself. Why not to make a perfectly clear correct
template?

About alert() in the particular: it is actually
window.alert() (a method of the host object). So you want DOM, but w/o
DOM? The bird won't fly this way ;-)
XML doesn't have DOM, it is just a data source as I said already. It
has though a node-based structure you can handle /during the
transformation into resulting document/ using XPath.

Jul 20 '06 #7

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

Similar topics

0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
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,...
1
8893
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
8861
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...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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();...
0
4366
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
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

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.