How to get count of childnodes in XML file using XQuery
Asked Answered
M

1

12

I want to get or return the number of item(<recROw></recROw>) in an xml file using the XQUERY. Is there an easy way to do that in XQuery?

Here is my sample XML data:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<DailyRecord>
  <recROw>
    <id>1</id>
    <name>John Smith</name>
    <gender>male</gender>
    <status>active</status>
  </recROw>
  <recROw>
    <id>2</id>
    <name>James Bond</name>
    <gender>male</gender>
    <status>active</status>
  </recROw>
<DailyRecord>

Any help and ideas would be appreciated. Thank you in advance!

Mellow answered 21/6, 2013 at 4:21 Comment(3)
What have you tried? I mean besides asking us.Fertilizer
u mean number of nodes ?Zeeland
Yes number of nodes in an item(<recROw></recROw>)Mellow
A
3

Try

count(/DailyRecord/recROw)
Ares answered 21/6, 2013 at 7:27 Comment(2)
Okay. Sorry I'm just a beginner about XQuery and Java. Thanks for downing!Mellow
upvoted the question, thank you for posting your question in a precise manner.Flunky

© 2022 - 2024 — McMap. All rights reserved.