By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,847 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

Displaying All Siblings of a Text Node

P: 3
Hello,

I am a begginer to JavaScript (as you can probably see) currently working on a web page to display equipment info when "MouseOver"-ing a picture of the equipment. The info is stored in an XML file that has been exported from an Access 2002 database.

Upon MouseOver, my script calls the function getText(assetID) where "assetID" is a four-digit number depending on the MouseOver area. (example: "3631")

I need something that searches the XML file for

Expand|Select|Wrap|Line Numbers
  1. <Asset_x0020_Number>3631</Asset_x0020_Number>
  2.  
and then adds all of the siblings of that node to a String.

This is what I have so far, but I'm missing the crucial piece.

Expand|Select|Wrap|Line Numbers
  1.  
  2.         function getText(assetID)
  3.             {
  4.             var text = assetID + '\n'; //the first thing I want is the assetID
  5.             var sibling;
  6.             var numberOfSiblings;
  7.  
  8.             for(var counter=0; counter<numberOfSiblings; counter++)
  9.                 {
  10.  
  11.                 //code here to make "sibling" be the next sibling, and the next one after that one the next iteration
  12.  
  13.                 text=text + sibling + '\n';
  14.                 }            
  15.  
  16.             }
  17.  
  18.  

There might be a way to do it all at once, but I have no clue as to how.

here is the piece of equipment with assetID 3631

Expand|Select|Wrap|Line Numbers
  1. <CONVEYOR_x0020__x0028_BELT_x0029_>
  2.     <Asset_x0020_Number>3631</Asset_x0020_Number>
  3.     <Unit_x0020_Number>30058C1</Unit_x0020_Number>
  4.     <Serial_x0020_Number>300235BEC1</Serial_x0020_Number>
  5.     <Remark>Crusher Discharge Belt</Remark>
  6.     <NOTES><![CDATA[[in Drawing 42-300 reducer=TDT515] [D-42-300  mentions "24" long type G.M. screw Take-Up under TAILSHAFT]]]></NOTES>
  7.     <Motor>81925</Motor>
  8.     <V-belts>BX83</V-belts>
  9.     <_x0023__x0020_of_x0020_V-belts>3</_x0023__x0020_of_x0020_V-belts>
  10.     <Reducer>1111115</Reducer>
  11.     <Drive_x0020_Sheave_x0020__x0028__x0022__x0029_>5.0 Pitch Diameter</Drive_x0020_Sheave_x0020__x0028__x0022__x0029_>
  12.     <Driven_x0020_Sheave_x0020__x0028__x0022__x0029_>18.4 Pitch Diameter</Driven_x0020_Sheave_x0020__x0028__x0022__x0029_>
  13.     <Drive_x0020_Sheave_x0020_Bushing_x0020__x0028__x0022__x0029_>1-1/8 (#1615)</Drive_x0020_Sheave_x0020_Bushing_x0020__x0028__x0022__x0029_>
  14.     <Driven_x0020_Sheave_x0020_Bushing_x0020__x0028__x0022__x0029_>1-1/4 (#2517)</Driven_x0020_Sheave_x0020_Bushing_x0020__x0028__x0022__x0029_>
  15.     <Belt_x0020_Length_x0020__x0028_feet_x0029_>112</Belt_x0020_Length_x0020__x0028_feet_x0029_>
  16.     <Belt_x0020_Type>1000108</Belt_x0020_Type>
  17.     <Head_x0020_Shaft_x0020_Size>2-15/16</Head_x0020_Shaft_x0020_Size>
  18.     <Tail_x0020_Shaft_x0020_Size>2-7/16</Tail_x0020_Shaft_x0020_Size>
  19.     <Capacity_x0020__x0028_MTPH_x0029_>240</Capacity_x0020__x0028_MTPH_x0029_>
  20. </CONVEYOR_x0020__x0028_BELT_x0029_>
  21.  
Thank you everyone!!!

PS: if there's an Access wizard in the crowd, I was wondering if there was a way to make Access automatically update the XML files or to link the Javascript directly into the database (which would be the ideal thing)

PPS: I hope this is in the right forum!
Jul 31 '08 #1
Share this Question
Share on Google+
5 Replies


acoder
Expert Mod 15k+
P: 16,027
This link should help you get started. Good luck!
Jul 31 '08 #2

P: 3
This link should help you get started. Good luck!
I now have
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <script type="text/javascript" src="CONVEYOR(BELT).xml>
  4.             function writeText(assetID)
  5.                 {
  6.                 var txt=""; 
  7.                 var sibling;
  8.                 var x=CONVEYOR(BELT).documentElement.childNodes; //I'm pretty sure this is where I go wrong since I'm trying to load ALL conveyors instead of the children of a specific conveyor.
  9.  
  10.                 for(var i=0; i<x.length; i++)
  11.                     {
  12.                     text=text + x[i].nodename + ": " + x[i].childNodes[0].nodeValue + '\n';
  13.                     }            
  14.  
  15.                 document.getElementById("desc").innerHTML=txt;
  16.                 }
  17.  
  18.         </script>
  19.     </head>
  20.  
  21.     <body>
  22.         <img src="300-899-8101-01.jpg" width=4516 height=2873 alt="Flowsheet" usemap="#flowsheetmap">
  23.         <map id="flowsheetmap" name="flowsheetmap">
  24.  
  25.  
  26.  
  27.         <area shape="poly" coords="775,525 , 1040,530 , 1040,550 , 775,565"
  28.         onclick="writeText(3631)"/>
  29.  
  30.         <p id="desc"></p>
  31.     </body>
  32. </html>
  33.  
and it doesn't display anything. (it used to display whatever I initialized "txt")

I think the problem is that I don't understand how to select the specific CONVEYOR that has "<Asset_x0020_Number>3631</Asset_x0020_Number>" as a child.

More complete extract from XML file:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="CONVEYOR%20(BELT).xsd">
  3. <CONVEYOR_x0020__x0028_BELT_x0029_>
  4.     <Asset_x0020_Number>3631</Asset_x0020_Number>
  5.     <Unit_x0020_Number>30058C1</Unit_x0020_Number>
  6.     <Serial_x0020_Number>300235BEC1</Serial_x0020_Number>
  7.     <Remark>Crusher Discharge Belt</Remark>
  8.     <NOTES><![CDATA[[in Drawing 42-300 reducer=TDT515] ]]></NOTES>
  9.     <Motor>81925</Motor>
  10.     <V-belts>BX83</V-belts>
  11.     <_x0023__x0020_of_x0020_V-belts>3</_x0023__x0020_of_x0020_V-belts>
  12.     <Reducer>1111115</Reducer>
  13.     <Drive_x0020_Sheave_x0020__x0028__x0022__x0029_>5.0 Pitch Diameter</Drive_x0020_Sheave_x0020__x0028__x0022__x0029_>
  14.     <Driven_x0020_Sheave_x0020__x0028__x0022__x0029_>18.4 Pitch Diameter</Driven_x0020_Sheave_x0020__x0028__x0022__x0029_>
  15.     <Drive_x0020_Sheave_x0020_Bushing_x0020__x0028__x0022__x0029_>1-1/8 (#1615)</Drive_x0020_Sheave_x0020_Bushing_x0020__x0028__x0022__x0029_>
  16.     <Driven_x0020_Sheave_x0020_Bushing_x0020__x0028__x0022__x0029_>1-1/4 (#2517)</Driven_x0020_Sheave_x0020_Bushing_x0020__x0028__x0022__x0029_>
  17.     <Belt_x0020_Length_x0020__x0028_feet_x0029_>112</Belt_x0020_Length_x0020__x0028_feet_x0029_>
  18.     <Belt_x0020_Type>1000108</Belt_x0020_Type>
  19.     <Head_x0020_Shaft_x0020_Size>2-15/16</Head_x0020_Shaft_x0020_Size>
  20.     <Tail_x0020_Shaft_x0020_Size>2-7/16</Tail_x0020_Shaft_x0020_Size>
  21.     <Capacity_x0020__x0028_MTPH_x0029_>240</Capacity_x0020__x0028_MTPH_x0029_>
  22. </CONVEYOR_x0020__x0028_BELT_x0029_>
  23. <CONVEYOR_x0020__x0028_BELT_x0029_>
  24.     <Asset_x0020_Number>7542</Asset_x0020_Number>
  25.     <Unit_x0020_Number>300740BEC001</Unit_x0020_Number>
  26.     <Serial_x0020_Number>300740BEC001</Serial_x0020_Number>
  27.     <Remark>Rail Discharge Coal Conveyor</Remark>
  28. </CONVEYOR_x0020__x0028_BELT_x0029_>
  29. </dataroot>
  30.  
The XML that Access export are stored in a butt-ugly format, but unfortunately there's nothing I can do about that.

Another stumbling block that I can see is the fact that the equipment with AssetID 3787 (a different one) would NOT be in CONVEYOR(BELT) but rather in CONVEYOR(SCREW).
I'm guessing some sort of search function would be necessary since multiple files have to be examined... Does anyone have any idea?

Also, and BIG thanks to acoder! :D
Jul 31 '08 #3

acoder
Expert Mod 15k+
P: 16,027
You first need to import the XML file. Here's one example and here's another.

Also remove the src attribute from the script tag.
Aug 1 '08 #4

P: 3
You first need to import the XML file. Here's one example and here's another.

Also remove the src attribute from the script tag.
I found a bunch of errors in the way the XML files were structured and built, so it'll be a while (probably a long one) until I can try to finish this. Normalization, here I come!

More importantly, thank you for your time and your help!
Aug 5 '08 #5

acoder
Expert Mod 15k+
P: 16,027
No problem. Post back with your solution (or more questions ;)) once you have the XML problems ironed out.
Aug 5 '08 #6

Post your reply

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