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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.