473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Reading XML with Javascript

I'm extremely new to XML, tell me what needs to be fixed in my XML file
as well as in my javascript.

My XML file looks like this:

<?xml version="1.0" encoding="iso-8859-1"?>

<imapmail>
<message>
<subject>Testing, 123</subject>
<sender>Name &lt;email@example.com&gt;</sender>
<date>1/2/03</date>
<size>640 KB</size>
<read>0</read>
</message>
</imapmail>

I'm accessing it with this javascript:

var sender =
xmlDocument.getElementsByTagName("sender").item(0) .firstChild.data;

I ultimately want to user to see that the sender is "Name
<em***@example.com>". With the way the XML file is currently set up
(sender is Name &lt;email@example.com&gt;), the only that shows up
on the javascript end is Name. Is the way I'm storing it in my XML file
the best way to be doing it?

Thanks for your help,
Trevor

Jan 16 '06 #1
4 1398


Trevor wrote:

<imapmail>
<message>
<subject>Testing, 123</subject>
<sender>Name &lt;email@example.com&gt;</sender>
<date>1/2/03</date>
<size>640 KB</size>
<read>0</read>
</message>
</imapmail>

I'm accessing it with this javascript:

var sender =
xmlDocument.getElementsByTagName("sender").item(0) .firstChild.data;
The variable sender should then have a string value with
'Name <em***@example.com>'
I ultimately want to user to see that the sender is "Name
<em***@example.com>". With the way the XML file is currently set up
(sender is Name &lt;email@example.com&gt;), the only that shows up
on the javascript end is Name.


Well how exactly do you use sender later? I am sure if you do e.g.
alert(sender)
you will see the string I have outlined above or if you do
document.body.appendChild(document.createTextNode( sender))
where document is a HTML document object will then show that string at
the end of the document.body.

I suspect you do e.g.
someHTMLElement.innerHTML = sender
and that way you cause the HTML parser to try to parse
'Name <em***@example.com>'
which then will cause the parser to somehow try to interpret
<em***@example.com> as a tag of an element in HTML and it can't do much
with that. Of course it does not make sense to use innerHTML to parse a
string which does not contain HTML markup.

But enough guessing, what exactly are you doing with sender?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 16 '06 #2
You guessed right, it's being written using innerHTML. I need to write
that value along with other markup which is why I'm doing it that way.
But I did figure it out. I'm just splitting <sender>Name
&lt;email@example.com&gt;</sender> into
<sendername>Name</sendername> and
<senderemail>em***@example.com</senderemail>. That's easier to deal and
it makes more sense in the structure of my XML document.

Jan 17 '06 #3
JRS: In article <11*********************@o13g2000cwo.googlegroups. com>,
dated Sun, 15 Jan 2006 23:52:43 remote, seen in
news:comp.lang.javascript, Trevor <tr*********@gmail.com> posted :
I'm extremely new to XML, tell me what needs to be fixed in my XML file
as well as in my javascript. <date>1/2/03</date>


Change the date format to something incompatible with FFF. Hopefully
that will not require upgrading any formal standards.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Jan 17 '06 #4
Thank you for the advice, I'll make sure I take care of that.

Jan 18 '06 #5

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

Similar topics

6
by: Eddie | last post by:
When I use JavaScript to read an element's textDecoration style, I only get one value even if there are more than one in the sytle sheet. For example if the text-decoration is defined as:...
1
by: Roger Godefroy | last post by:
Hi there... I want to read fieldvalues from out of a dynamicaly created table (php). But this has to be done by JavaScript. Every row of the table has a select-box, inputbox and a order-button....
3
by: Catherine Lynn Smith | last post by:
I'm looking through the client side javascript reference and there's some mighty useful information in here, but it is not very specific on 'reading' information from event handlers. In the...
3
by: Christian Caron | last post by:
Hi all, I have a page which contains the following tag: <head> <meta name="date_modified" content="20030730" /> </head> (...) <script> (...)
0
by: Ben | last post by:
Hello, I am reading a web page using httpwebrequest and httpwebresponse that contains HTML and javascript code. When I read the page I can only read the translated HTML code. I want to read the...
1
by: enrique | last post by:
Our server-side software is reading in Big5-encoded data as ASCII when the web pages are generated. It seems to work most of the time, since the HTML meta tag is declaring Big5 as the charset. ...
9
by: Mike Reed | last post by:
I must be having a "senile" day! I cannot recall, nor get to work, code to read a cookie's expiration date/time in an ASP page/VBScript. What am I missing? *** Sent via Developersdex...
1
by: paulnightingale | last post by:
Hi I've got a ticker tape that is written in Java Script 1.2 which displays text that has to be currently changed in the program code. What I want to do is to find the bit of javascript to get the...
6
by: Melih Onvural | last post by:
I need to execute some javascript and then read the value as part of a program that I am writing. I am currently doing something like this: import htmllib, urllib, formatter class...
1
by: waynes | last post by:
Hello group, first time here. I have question regarding reading form post variables. I have a forms processor that dynamically reads a form, for example: For x = 1 To Request.Form.count() ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.