JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 27th, 2001, 05:47 AM
BJohnson BJohnson is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Madrid, Spain
Posts: 4 BJohnson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Javascript and XML attributes

Hello,

I am trying to do something with JavaScript that would be quite
easy to do with XSL, but for reasons that would take to long to
explain, I need to do it in JavaScript.

Basically, If I have the following simple XML:

<Questionaire>
<Section title="section1">
<Question>
.
.
.
</Question>
</Section>
<Section title="section2">
<Question>
</Question>
</Section>
</Questionaire>

How do I extract/get the section attributes?

I have the following Javascript to process the file:

<HTML>
<head><title>XML File output</title></head>
<XML ID="xml_file" SRC="questionaire.xml"></XML>

<BODY>
<SCRIPT LANGUAGE="JavaScript1.1">

function parse_xml( node )
{
section_list = xml_file.XMLDocument.selectNodes( "Questionaire/Section" );

//Loop through the sections
for( i = 0; i < section_list.length; i++ )
{
// I want to get the attribute here
section_array = new section( section_list[i] );

question_list = section_list[i].selectNodes( "Question" );

// Now loop through each question in the section
for( j = 0; j < question_list.length; j++ )
{
question_array= new question( question_list[j] );

}
}
}
</SCRIPT>
</BODY>
</HTML>

I know that the logical solution would be to change the XML section
definition to the following:
<Section>
<SectionTitle>section1</SectionTitle>
<Question>
</Question>
</Section>

But the other way is still standard XML and you should be able
to get to the attribute with JavaScript.

I tried different combinations of the following with no success
selectSingleNode( Section[@title])

Any Ideas???

Brady

Last edited by BJohnson : September 27th, 2001 at 05:53 AM.

Reply With Quote
  #2  
Old October 6th, 2001, 08:51 AM
Alexandr Alexandr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Belarus
Posts: 30 Alexandr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
hi BJohnson

how about this line

var title = section_list[i].getAttribute("title")

Reply With Quote
  #3  
Old October 8th, 2001, 02:44 AM
BJohnson BJohnson is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Madrid, Spain
Posts: 4 BJohnson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile It works!!

Alexandr,

That's great, its just that simple!

I have a book that explains XML and has some
examples on how to use JavaScript with XML,
but it doesnt include that method.

I was also searching all over the internet
looking for a Complete list of JavaScript
XML functions. Do you know of anything.

Thanks alot for your help.

Brady

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Javascript and XML attributes

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap