You can do this using XML rules. Check out a chapter of the same name in the InDesign CS5 Scripting Guide (VB version). There you will find many examples.
You can indicate which nodes you want to process with XPath. For example, this will match on every XML element in the XML structure:
Public Property Get xpath xpath = "//*" End Property
And this matches all following sibling XML elements of the first "item" XML element:
Public Property Get xpath xpath = "/xmlElement/item/following-sibling::*" End Property
Kasyan, thank you for the reply. I looked at that part in the book and I have tried using the example code, but I am having difficulty in understanding how it is being used, maybe you, or someone can help to explain it.
So in an example like this:
Public Property Get name
name = "ProcessChildrenRule"
Public Property Get xpath
xpath = "//XMLElement"
Public Function apply(myXMLElement, myRuleProcessor)
.XMLAttributes.Item(1).Value & vbCr
apply = false
There are 5 things that I am not understanding.
1. How is "xpath" being used? I don't see another occurance of it other than when the variable xpath is set.
2. How is name being used? I don't see another occurance of it other than when the variable name is set.
3. Why is "Public Function apply" created in each class? In the examples in the book, that function exists in each Class. Why not just create the function outside of the class and call it from inside the class?
4. Where is the "apply" function being called from? It doesn't get called from inside or outside the class on the example pages anywhere?
5. Where are the values of myXMLElement and myRuleProcessor being set before they are used in the function?
Even in the examples you gave, once I set the xpath value, what do I do with it after that? How do I write out the value of what I am searching for with the xpath?
So going back to my original question, if I set xpath = "/devices/device", how do I loop through each "device" node and write them out? That is where it is breaking down for me. I haven't seen any examples in the book or in the downloaded example code that show how to do that.