Announcement

Collapse
No announcement yet.

count number of XML elements

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • count number of XML elements

    Consider this problem:

    There is a variable holding an XML snippet that could have multiple repeating nodes.

    <patients>
    <patient gender="m">Barney</patient>
    <patient gender="f">Sue</patient>
    </patient>

    Question: How to get the count of the number of patient nodes in Javascript? Is there an easy XPath count function?

  • #2
    Code:
    msg['patients']['patient'].length()
    Daniel Svanstedt
    Software Engineer
    Mirth Corporation

    Want professional services, support, and enterprise or virtual appliances? It's all available from the Mirth Corporation:
    Mirth Support | Mirth Training | Mirth Appliances | Online Training | Developer Q&A

    Don't forget, Mirth Support gives you access to all of our online training videos, and silver support gives you access to developer Q&As!

    Comment


    • #3
      Originally posted by Philoushka View Post
      Consider this problem:

      There is a variable holding an XML snippet that could have multiple repeating nodes.

      <patients>
      <patient gender="m">Barney</patient>
      <patient gender="f">Sue</patient>
      </patient>

      Question: How to get the count of the number of patient nodes in Javascript? Is there an easy XPath count function?
      If you reference patient it will be a list, so you can use an e4x command to get the size:
      https://wso2.org/project/mashup/0.2/...uickstart.html

      I believe you can just use .length() on your patient list.
      Jacob Brauer
      Director, Software Development
      NextGen Healthcare

      sigpic

      Comment


      • #4
        Thanks Jacob and Dan.

        I tried .count and .length, and was attempting to use them as properties (i.e. no parenthesis). Now that you've pointed out that they're functions, everything's good.

        Thanks again!

        Comment

        Working...
        X