473,769 Members | 6,499 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>Testin g, 123</subject>
<sender>Name &lt;email@examp le.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.get ElementsByTagNa me("sender").it em(0).firstChil d.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@examp le.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 4732


Trevor wrote:

<imapmail>
<message>
<subject>Testin g, 123</subject>
<sender>Name &lt;email@examp le.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.get ElementsByTagNa me("sender").it em(0).firstChil d.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@examp le.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.a ppendChild(docu ment.createText Node(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@examp le.com&gt;</sender> into
<sendername>Nam e</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************ *********@o13g2 000cwo.googlegr oups.com>,
dated Sun, 15 Jan 2006 23:52:43 remote, seen in
news:comp.lang. javascript, Trevor <tr*********@gm ail.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.demo n.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
20545
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: text-decoration : underline overline; when reading element.currentStyle.textDecoration I only get "underline"!! What's worse is that element.style.textDecorationUnderline returns
3
2681
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
3123
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. However, every now and then certain ASCII characters, like the quote (") for example, gets read in and creates Javascript errors when the browser renders them. I think this is a direct side effect of processing our Big5-encoded files as ASCII. ...
9
5522
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 http://www.developersdex.com ***
6
3576
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 myparser(htmllib.HTMLParser): insave = 0 def start_div(self, attrs): for i in attrs: if i == "id" and i == "pr":
0
9423
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
10045
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
9993
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
9863
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
7406
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
6672
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
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.