Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XML count node
#1
If I want to count the amount of <Pair> nodes within <FolderPairs> in the below example, how do I use the 'Count()' (If applicable in this example). I got 'Count' from the helpfile:

Code:
Select All      Help
[g]#Count()
Gets the number of nodes in XML, including attributes.

Below I used .len and it returns 2 which is seems correct as <FolderPairs> has 2 x child nodes: <Pair>...</Pair>
Is this correct? in other words: Can I use .len If I specified x.Path correctly?:
FreeFileSync/MainConfig/FolderPairs/* (see below in example).

To avoid confusion, I want to count how many times <Pair>...</Pair> occurs.

Macro xml - count nodes - example 1
Code:
Select All      Help
;This example should output the <Pair> count under the parentnode <FolderPairs>

ARRAY(IXmlNode) a
str xml=
;<?xml version="1.0" encoding="UTF-8"?>
;<FreeFileSync XmlFormat="6" XmlType="GUI">
;;;;;<MainConfig>
;;;;;;;;;<FolderPairs>
;;;;;;;;;;;;;<Pair>
;;;;;;;;;;;;;;;;;<Left>c:\doc</Left>
;;;;;;;;;;;;;;;;;<Right>d:\doc</Right>
;;;;;;;;;;;;;</Pair>
;;;;;;;;;;;;;<Pair>
;;;;;;;;;;;;;;;;;<Left>c:\music</Left>
;;;;;;;;;;;;;;;;;<Right>d:\music</Right>
;;;;;;;;;;;;;</Pair>
;;;;;;;;;</FolderPairs>
;;;;;;;;;<OnCompletion/>
;;;;;</MainConfig>
;;;;;<GuiConfig>
;;;;;;;;;<HandleError>Popup</HandleError>
;;;;;;;;;<MiddleGridView>Action</MiddleGridView>
;;;;;</GuiConfig>
;</FreeFileSync>

IXml x._create
IXmlNode e
x.FromString(xml)

int i
e=x.Path("FreeFileSync/MainConfig/FolderPairs/*" a 1)
out a.len ;; Using '.len' to count the CHILD nodes from '<FolderPairs>'
Reply
#2
a.len is correct.
Reply
#3
Thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)