473,406 Members | 2,220 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,406 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 4715


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:...
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> (...)
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...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
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...
0
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,...
0
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...

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.