Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Reading XML with Javascript

Reply
Thread Tools

Reading XML with Javascript

 
 
Trevor
Guest
Posts: n/a
 
      01-16-2006
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
<(E-Mail Removed)>". 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

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      01-16-2006


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 <(E-Mail Removed)>'

> I ultimately want to user to see that the sender is "Name
> <(E-Mail Removed)>". 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 <(E-Mail Removed)>'
which then will cause the parser to somehow try to interpret
<(E-Mail Removed)> 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/
 
Reply With Quote
 
 
 
 
Trevor
Guest
Posts: n/a
 
      01-17-2006
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>(E-Mail Removed)</senderemail>. That's easier to deal and
it makes more sense in the structure of my XML document.

 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      01-17-2006
JRS: In article <(E-Mail Removed). com>,
dated Sun, 15 Jan 2006 23:52:43 remote, seen in
news:comp.lang.javascript, Trevor <(E-Mail Removed)> 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)
 
Reply With Quote
 
Trevor
Guest
Posts: n/a
 
      01-18-2006
Thank you for the advice, I'll make sure I take care of that.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Working with XML in JavaScript / Как работать с XML в Javascript'е? noff Javascript 0 06-14-2007 12:46 PM
UnauthorizedAccessException when reading XML files (no problem when reading other file-types) blabla120@gmx.net ASP .Net 0 09-15-2006 02:08 PM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Reading XML with Javascript Trevor Javascript 4 01-18-2006 05:07 AM
Acrobat javascript for writing/reading xml files John Nash Javascript 0 04-17-2004 06:24 AM



Advertisments