0

Hi I do have XML as below:

<?xml version="1.0" encoding="UTF-8"?>
<library>
      <book publisher="Del Rey">
            <series>The Lord of the Pings</series>
            <title>Way Station</title>
            <author>Clifford D. Simak</author>
      </book>
      <book publisher="Del Rey">
            <series>The Lord of the Rings</series>
            <title>The Fellowship of the Ring</title>
            <author>J.R.R. Tolkien</author>
      </book>
      <book publisher="Del Rey">
            <series>The Lord of the Rings</series>
            <title>The Two Towers</title>
            <author>J.R.R. Tolkien</author>
      </book>
      <book publisher="Del Rey">
            <series>The Lord of the Rings</series>
            <title>The Return of the King</title>
            <author>J.R.R. Tolkien</author>
      </book>
      <book publisher="Ace">
            <series>Lord Darcy</series>
            <title>Too Many Magicians</title>
            <author>Randall Garrett</author>
      </book>
      <book publisher="Ace">
            <series>Lord Darcy</series>
            <title>Murder and Magic</title>
            <author>Randall Garrett</author>
      </book>
      <book publisher="Ace">
            <series>Lord Darcy</series>
            <title>The Napoli Express</title>
            <author>Randall Garrett</author>
      </book>
      <book publisher="Ace">
            <series>Lord Darcy</series>
            <title>Lord Darcy Investigates</title>
            <author>Randall Garrett</author>
      </book>
</library>

I am trying to create an xpath expression to count the number books,under <library> .. </library> using count() . But I couldn't figure out.

Any help in this regard?

Edited by arupface

2
Contributors
1
Reply
5
Views
3 Years
Discussion Span
Last Post by gusano79
0

What have you tried so far? Showing us what you've tried will help us understand better where your problem is.

In this case, you want count(/library/book). The query /library/book returns all of the book elements, which you should pass as a parameter to the count function so it can do what it does.

Are you using an XML editor that lets you perform XPath queries while you work? I've found it to be extremely helpful; I normally use XMLPad.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.