473,324 Members | 2,501 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,324 software developers and data experts.

Element vs. Attribute?

57
Hi,
I've been racking my head and searching the net (and these forums) to try and get around this problem. I have radio stations stored in an xml file (each state has their own xml file). I'm able to display each state's stations just fine on their own page, but the problem I'm running into comes when I want to display stations in a timezone page. Some states are in two different timezones and therefore have stations in two different timezones. I've posted basically the same question in the javascript forum to see if my javascripts need help, because one script will work in Firefox and not IE and another script will work in IE and not Firefox.

My xml question is this: should I list the timezone for each station as an attribute of the station tag or as its own separate element?

Should it be this:
Expand|Select|Wrap|Line Numbers
  1. <station timezone="CT">
  2.  
or this:
Expand|Select|Wrap|Line Numbers
  1. <station>
  2. <timezone>CT</timezone>
  3. </station>
  4.  
Here's a sample xml file:
Expand|Select|Wrap|Line Numbers
  1. <stations>
  2.     <station timezone="ET" ET="">
  3.         <city>Chattanooga</city>
  4.         <freq>99.9 FM</freq>
  5.     </station>
  6.     <station timezone="ET" ET="">
  7.         <city>Knoxville</city>
  8.         <freq>107.9 FM</freq>
  9.     </station>
  10.     <station timezone="CT" CT="">
  11.         <city>Memphis</city>
  12.         <freq>93.1 FM</freq>
  13.     </station>
  14.     <station timezone="CT" CT="">
  15.         <city>Nashville</city>
  16.         <freq>95.7 FM</freq>
  17.     </station>
  18. </stations>
  19.  
Here's the javascripts I have, just for reference (they're trying to display only the <city> elements from stations that are in Central Time):

This works in FF but not IE:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     xmlDoc=loadXMLDoc("stations.xml");
  3.     x=xmlDoc.getElementsByTagName("city");
  4.     for (i=0;i<x.length;i++)
  5.         {
  6.         if (x[i].parentNode.hasAttribute("CT"))
  7.             {
  8.             document.write(x[i].childNodes[0].nodeValue)
  9.             document.write("<br />")
  10.             }
  11.         }
  12. </script>
  13.  
This script works in IE, but not in FF (I thought FF had built-in xpath support?):
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     xmlDoc=loadXMLDoc("stations.xml");
  3.     xmlDoc.setProperty("SelectionLanguage", "XPath");
  4.     x=xmlDoc.selectNodes("//station[@timezone='CT']/city");
  5.     for (i=0;i<x.length;i++)
  6.         {
  7.         document.write(x[i].childNodes[0].nodeValue)
  8.         document.write("<br />")
  9.         }
  10. </script>
  11.  
The first javascript example is why I have the blank CT="" and ET="" attributes in the xml file.

Anyway, if you have any idea what's going here and how to do this...THANK YOU!
May 22 '07 #1
2 2035
dorinbogdan
839 Expert 512MB
You can use either attribute or element as timezone, depending which way is better for javascript.
I will also think more about a cross-browser solution.
May 22 '07 #2
drhowarddrfine
7,435 Expert 4TB
document.write is not part of the DOM (and I think not part of any standard?). DOM methods are always safer and better to use. document.write does not work in XML at all, I believe.

(Reolletions of one who has not messed with this in too long)
May 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ingrid | last post by:
Am I right in thinking that datatyping at element level ie <xs:element name="num" type="xs:integer"> and specifying a choice of attribute values ie <xs:attribute name="kind"> <xs:simpleType>...
4
by: Gordon Dickens | last post by:
I have target xml to generate from schema. All of the XML instances have the same global element i.e. <base>. I would like to combine all of the schemas into a single schema where I could...
4
by: celerystick | last post by:
This is an xsl question, comp.infosystems.www.authoring.stylesheets were not able to help , here goes .... With one xml file containing repeated element <subject>: ...
1
by: Wayne Lian via .NET 247 | last post by:
Hi all, Just wonder anyone have encountered this problem before?I tried using XMLSPY debugger and I can get the correct outputfor my XSLT transformation, however in .net, aftertransformation the...
0
by: magister | last post by:
Hello, I want to have a unique Quesiton Id key for each question under section. Not for every question in the Typed DataSet. Is there anyway I can do this...? Thanks, here is my typed...
6
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a...
16
by: TT (Tom Tempelaere) | last post by:
Hi all, I created an XSD to define the structure of an XML file for my project. I made an XML file linked to the XSD using XmlSpy. The problem is that if I read the file using .NET XmlDocument...
4
by: Eric | last post by:
Attached is an example of my question. Note the "values" attribute is optional. Also the <valuesub-element is optional. Here, the XML can contain, 1 or both or neither. I would like to allow...
3
markmcgookin
by: markmcgookin | last post by:
Hi, I have the following XML <AnswerList xmlns="http://tempuri.org/ALPS_Assessmentv1p1_RESCO_Schema.xsd"> <DateTimeLastSaved>12:12:12 1900</DateTimeLastSaved> <UserName>Bob</UserName>...
2
by: mlb5000 | last post by:
I seem to be having issues validating an XML document using my schema. Both are below: The Schema: <?xml version="1.0" encoding="UTF-8"?> <xs:schema...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.