XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

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 October 4th, 2004, 05:03 AM
amstel_za amstel_za is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 270 amstel_za User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 10 h 47 m 37 sec
Reputation Power: 5
Confusion with GetAttribute/GetElementsBytagName

Hi all,

I'm a little confused and was wondering whether someone could help explain something to me. My questions are located to the right of the tags preceeded by a * and at the end of the XML example.

Here is a simple XML file:

<Countries> *This is the document root isn't it?
<Argentina> *What is this then? the root as well??
<Pop>1000000</Pop>
<Area>2000000sqkm<Area>
</Argentina>
<Bolivia>
...etc...
</Bolivia>
</Countries>

I have an SVG document (map of the world) which I want to access an external XML file (containing data like the stuff)above). Now, when the user clicks on the SVG map, I want the data associated with that click to be matched in the XML file and returned to the browser.

So...in the SVG document, I have an id field which contains the countries name in it. I will then extract this when onclick is activated and then use GetElementsByTagName to get the correct "row" of XML data, then use GetAttribute to select the child nodes underneath.

Now, that is my understanding of what I need to do...but is it right and more importantly efficient???

I keep getting confused with the document root and the childs underneath since virtually all examples of XML documents illustrate this:

<ListCountries> *This is the document root isn't it?
<Country> *What is this then? the root as well??
<Pop>1000000</Pop>
<Area>2000000sqkm<Area>
</Country>
<Country>
...etc...
</Country>
</ListCountries>

--> in the above example...how on earth am I to use the GetElementsByTagName to get the appropriate "row" of data since they're all called Country??? Is it acceptable to have an XML file such as the one at the top of the list??

Thanx
Ben

Reply With Quote
  #2  
Old October 4th, 2004, 05:53 AM
Miska's Avatar
Miska Miska is offline
Madden Maniac
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2001
Location: Finland
Posts: 519 Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 3 h 47 m 50 sec
Reputation Power: 8
In your first example the countries element is the root and one has to have a root element in a xml-file. Argentina on the other hand is not a root element rather than just a normal xml element.

On the second example the listcountries is the root once again and the country element are just normal xml elements.

And as an answer to your effiency question. Since you are using the GetElementsByTagName the first one is probably more efficient. The latter one can be done with GetElementsByTagName but you need to add some attribute information to the tag for finding the correct one e.g. <country name='finland'>

I suggest using the first one if you use getElementsByTagName...

-Miska-

Reply With Quote
  #3  
Old October 4th, 2004, 06:12 AM
amstel_za amstel_za is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 270 amstel_za User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 10 h 47 m 37 sec
Reputation Power: 5
Ah, okay, so in the 2nd example. I would have:

<Country>
...
</Country>
<Country>
...
</Country>

and then add name="whatever" to each <Country> element and then use GetAttribute to access the attribute element of Country to get all the child nodes?? So thereby skipping on the GetElementByTagName command since all the elements will have the same name (eg: Country?)

Which is faster or more acceptable in your view?

Thank you!!
Ben

Reply With Quote
  #4  
Old October 4th, 2004, 07:25 AM
Miska's Avatar
Miska Miska is offline
Madden Maniac
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2001
Location: Finland
Posts: 519 Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 3 h 47 m 50 sec
Reputation Power: 8
I would do it like the first one, but it all once again depends one the programming interface that you are using (I'm a PHP menace). If you are using DOM or something else (SAX, etc.). You're probably using the DOM looking from your description.

The latter on is better if you have a function like getElementByAttributeValue, though this function can be easily made to almost any programming language.

-Miska-

Reply With Quote
  #5  
Old October 5th, 2004, 06:10 AM
amstel_za amstel_za is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 270 amstel_za User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 10 h 47 m 37 sec
Reputation Power: 5
Miska, Okay, but how do you specify a DTD header for a document?? The same way as is already? If I have different elements under the root (1st example) then it'll be a massive DTD instead of the 2nd one which is easier.

Reply With Quote
  #6  
Old October 6th, 2004, 04:01 AM
Miska's Avatar
Miska Miska is offline
Madden Maniac
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2001
Location: Finland
Posts: 519 Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 3 h 47 m 50 sec
Reputation Power: 8
Quote:
Originally Posted by amstel_za
Miska, Okay, but how do you specify a DTD header for a document?? The same way as is already? If I have different elements under the root (1st example) then it'll be a massive DTD instead of the 2nd one which is easier.

That's true, but if you use XML Schema instead, then the first one is easily done as well...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Confusion with GetAttribute/GetElementsBytagName


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

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT