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:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old March 29th, 2001, 08:58 PM
gford gford is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Texas
Posts: 18 gford User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy

I am having trouble getting a node count from an XML data list.


<menu>
<catagory>
<title>Catagory One for the money</title>
<sub1>This is sub1 one</sub1>
<sub2>This is sub2 one</sub2>
<sub3>This is sub3 one</sub3>
</catagory>
<catagory>
<title>Catagory Two for the show</title>
<sub1>This is sub1 two</sub1>
<sub2>This is sub2 two</sub2>
</catagory>
</menu>

menu=new ActiveXObject ("MSXML.DOMDocument");
menu.load("XML FileName.xml");
testNode=menu.documentElement.firstChild;

document.write(testNode.firstChild.nodeName);
this yeilds ---> title

document.write(testNode.firstChild.nextSibling.nodeName);
this yeilds ---> sub1

document.write(testNode.firstChild.nextSibling.nextSibling.nodeName);
this yeilds ---> sub2

document.write(testNode.lastChild.nodeName);
this yeild ----> sub3
_________________________________________

What I need is a way to count these children while not knowing how many there are .... if any?
Comments on this post
Gran Roguismo agrees!

Reply With Quote
  #2  
Old March 30th, 2001, 02:01 AM
rdominy rdominy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 81 rdominy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to rdominy
One way you should be able to do this is as follows:

foundNodes=menu.documentElement.getElementsByTagName("*");

This will return a list and you should be able to use "foundNodes.length" to get a count of the items.

If you want specific tags just substite the tag in place of the "*".
Comments on this post
Gran Roguismo agrees!
__________________
Robert Dominy
About Guide for JavaScript
http://javascript.about.com
Software Consulting & Development
http://www.angusog.com

Reply With Quote
  #3  
Old March 30th, 2001, 05:08 AM
gford gford is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Texas
Posts: 18 gford User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
rdominy

Hey....thanks for the ("*") wild card info. I have not seen used with the getElementsByTagName before. When I try this however, I get a list of all nodes in the data list......in my case...."23" . What I want is to count the children of a node. As to my example;
<catagory>
<title>......
<sub1>......
<sub2>......
</catogory>

How do I count the Children under the <catagory> node? In this example I would be looking for a count of three children.

thanks,
gary

Reply With Quote
  #4  
Old March 30th, 2001, 06:04 AM
gford gford is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Texas
Posts: 18 gford User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up rdominy.....again

Well.....I played around with the code and I found a variation that worked!!! Most of my problem has been not quite understanding the xml dom structure.....but i know more now than i did.....
Thanks again for the ("*") hint!!!
gary

This does what i want.....which is to count the children of a node.....note the first thread xml data list. I'm sure the code can be more consice....but hey it works!

var menu;
menu = new ActiveXObject("MSXML.DOMDocument");
menu.load("TestDataXml.xml");
var testNode;
testNode = menu.documentElement.firstChild;
var findNodes;
findNodes2 = testNode.getElementsByTagName("*");
findNodesCount2 = findNodes2.length;
document.write(findNodesCount2 + "<br>");
document.write(findNodes2.item(2).nodeName + "<br>")
document.write("<hr>");
var i;
for (i = 0; i < findNodesCount2; i++) {
document.write(findNodes2.item(i).nodeName + " - ");
document.write(findNodes2.item(i).firstChild.nodeValue + "<br>");
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XML Node counting problem


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!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





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