473,516 Members | 3,488 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Displaying All Siblings of a Text Node

3 New Member
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
5 2127
acoder
16,027 Recognized Expert Moderator MVP
This link should help you get started. Good luck!
Jul 31 '08 #2
Telz
3 New Member
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
16,027 Recognized Expert Moderator MVP
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
Telz
3 New Member
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
16,027 Recognized Expert Moderator MVP
No problem. Post back with your solution (or more questions ;)) once you have the XML problems ironed out.
Aug 5 '08 #6

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

Similar topics

2
1489
by: Ian Gibbs | last post by:
Dear all, I'd like to know in the following XML, when I am looping through the server elements, how many of the previous servers had ldap-role values of YES or MASTER. <install-config> <servers> <server hostname="server1"> <ldap-role>NO</ldap-role>
7
2220
by: Tony Benham | last post by:
I am trying out a div which is a footer for a page, which contains a <p>zzzz</p> and a <a href yyyy>Link</a>, and I want the <p> element to be placed on the left of the div, and the <a> element on the right. I've put a float : right ; on <a> elements in the footer div. This seems to work fine in opera 7.11 & netscape 7, but in IE6 the <a> is...
2
1688
by: partridge | last post by:
I'm sure it's not mozilla's fault but I'm at a loss here. I'm loading the following XML data into a page using http_request: <?xml version="1.0" encoding="iso-8859-1"?> <forum> <message id="msg1"> <date>10/13/2005</date> <time>10:39 pm</time> <name>Josh</name>
2
1705
by: Gabe Moothart | last post by:
Hi, I need some help figuring out how to do something in xslt. I have an xml document with a list of items. Each item in turn can have a list of options, like so: <item> <stuff>Item 1 Stuff</stuff> <option> <option_stuff>Option 1 Stuff</option_stuff> </option>
5
2799
by: hatsumoto | last post by:
Hello, I create an ActiveXObject("Msxml2.XMLHTTP") from my HTML page to submit (i.e. post) XML to a server. I can see the content of the XML response via javascript alert(xmlhttp.responseText). Is there a way to display the content of xmlhttp.responseText on a new page?? I tried document.write(xmlhttp.responseText) but this does not...
0
2170
by: saravanaVijayakumar | last post by:
I'm new to xml .. I had created a application such a way that I have to display the xml file in treeview control in C#.Net Application ... If I select the particular Node it should display the attributes of that node in DataGrid But I am displaying the attributes in dataGrid if i use the following Code XmlNode x = ...
6
1964
by: lejason | last post by:
I am having trouble with a really simple problem! haha. How do you display that data from on xml file. Here is my xml file called "test.xml" <?xml version="1.0" encoding="iso-8859-1"?> <test> <person> <name>Jason</name> <color>blue</color> <number>16</number>
1
1260
by: seanh | last post by:
Hello, I am having problems on displaying deep node elements <DDD> and <EEE> using a stylesheet to display it in html. In the ouput that I am trying to get (the part with the (******) below) is where I am having the problems,(the part with the (---) below) I was able to display. Can anyone please help. ...
2
2643
by: nicky123 | last post by:
Hi everyone, This is a brief description that I have provided for parsing & displaying an XML document using DOM API. Please feel free to post your own comments & views regarding this discussion. Thank you. The first step of parsing an XML document is to import the DOM API related classes such as :- java.io.* which...
0
7273
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7574
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7547
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5712
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
1620
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.