Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8306517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:20:50+00:00 2026-06-08T18:20:50+00:00

Sample XML. <node> <nodeid>28</nodeid> <account_no xsi:nil=true /> <address1>15 CANCUN CT</address1> <serial_no>112199543</serial_no> <x_lat>25.95513358000</x_lat> <y_lon>-97.49027147000</y_lon> <alarm>

  • 0

Sample XML.

<node>
<nodeid>28</nodeid>
<account_no xsi:nil="true" />
<address1>15 CANCUN CT</address1>
<serial_no>112199543</serial_no>
<x_lat>25.95513358000</x_lat>
<y_lon>-97.49027147000</y_lon>
<alarm>
  <alarmid>Outage</alarmid>
  <alarmtime>2012-07-30T14:46:29</alarmtime>
</alarm>
<alarm>
  <alarmid>Restore</alarmid>
  <alarmtime>2012-07-30T14:55:29</alarmtime>
</alarm>
</node>
<node>
<nodeid>67</nodeid>
<account_no>274192</account_no>
<address1>1618 CHIPINQUE DR</address1>
<serial_no>112199521</serial_no>
<x_lat>25.95286395000</x_lat>
<y_lon>-97.49323166000</y_lon>
<alarm>
  <alarmid>Outage</alarmid>
  <alarmtime>2012-07-30T14:46:29</alarmtime>
</alarm>
</node>
</ROOT>

I want to count the number of

<alarm>

elements the first node has as well as the second. I tried to do this in a for loop…

xmlDoc.getElementByTagName('alarm')[i].length;

this gives me all number of ‘alarm’ tags in the xml file. Which all i want is the current ‘node’ alarm elements. So here is what I want, I want for it to tell me the first has 2

<alarm>

tags and the second ‘node’ has 1

<alarm>

Just javascript no jQuery.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:20:51+00:00Added an answer on June 8, 2026 at 6:20 pm

    try this:

    var nodes = xmlDoc.getElementsByTagName('node'), //Get the <node> tags
        amountOfNodes = nodes.length
    
    for(var i = 0; i < amountOfNodes; i++) { //loop thru the nodes
    
       console.log(nodes[i].getElementsByTagName('alarm').length); //get the amount of <alarm> tags
    
    }
    

    EDIT
    Here’s a working example: Fiddle.

    Tell me if that solves your problem 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

XML File Sample <GateDocument> <GateDocumentFeatures> ... </GateDocumentFeatures> <TextWithNodes> <Node id=0/> MESSAGE SET <Node id=19/>
In the below sample XML, how to remove Entire B Node if E=13 using
It is simple enough to put the outer text of an XML node in
I need to load an XML source using Simple XML, duplicate an existing node
Possible Duplicate: A simple program to CRUD node and node values of xml file
Sample XML. <person> <name>Joe Dirt</name> <ssn>123-45-6789</ssn> <dob>07/04/1981</dob> </person> Sample Java Class public class Person(){
I have a sample xml file which looks like the one below: <Root> <SubOne>
This is the sample xml document : <bookstore> <book category=COOKING> <title lang=english>Everyday Italian</title> <author>Giada
Please see the sample xml given below. As per a requirement, I need to
I have a bit of xml file named Sample.xml which is shown below <?xml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.