After doing this though, some of the elements found won’t have a selector so you would need to either surround the Invoke Method with a Try/Catch or adjust the Input parameter so it doesn’t throw an error.
I hope this helps or atleast gets you on the right track.
thanks a lot for you reply! It works! I also have the following two challenges:
The code xmlDoc.Element(activities+"Activity").Element(activities+"Sequence").Attribute("DisplayName").Value finds the display name attribute of the Sequence element. However this Sequence element must be after the Activities element. But I would actually like to find all of the Sequence Elements in the code, including their (parent / child) path, independently on where these sequence Elements are.
Once I find an element such as ui element or sequence element, I would like to find all of its children, children of children etc, without losing the information about which level they are: level 1 (child) level 2 (child of child) etc.
I was getting an error that pointed to the position: “There are multiple root elements. Line 1, position 706” for example
So, I took your xml string, sequenceNode.Innerxml, and pasted the text into Word and performed a Word Count to get the character location that the error is pointing to. Then, just as a test, I split off all the text after that position and it got passed the error message.
Apparently, it’s not liking the fact that the beginning root elements are closed and a second group of root elements are started, if that makes sense. For example, where it says <\ui:OpenBrowser> closes the first root element, so everything after that point is causing the error.
I hope that helps identify the problem. This is not my expertise and I’m short of time, so I got to stop there in finding a solution for this.
Many thanks for your reply, that’s great! However I’m indeed developing a pretty tough code.
I went ahead and now I would like to extract all of the children nodes from a certain sequence: for each child, analyse the child of the child, for each child of the child, if exist analyse the child of the child of the child and so on…
I did it with approach in attachment, but how can I do it avoiding nested for each?
Furthermore, the file in attachment has an error that occurred when I isolated this piece of code in order to send it to you… Any idea why?
There is an error because you are using a variable in the Default value of a variable both which are in the same scope so it has not yet been declared and can not be used to declare another variable.
" Application nodes : Object reference not set to an instance of an object."
Application nodes is the scope or topmost sequence. Basically you can just use the same line that you declared the variable as inplace of the variable name.
New XmlNamespaceManager(new XmlDocument().NameTable)
But that might not be what you need. The alternative to that is to change the scope of the NamespaceManager variables to an inner scope so diagramTree is in an outer scope so it can be set before the other variables that use it, if that makes sense.
There must be a way to get all child nodes without looping through each one individually. I’ll need to play around with it and get back to you on that though.
There is also a way with lambda expressions in vb.net.
I have not looked into enough to confirm that, but basically you can take the list of nodes and run it through a .Select() and/or .Where()
You have a Try/Catch surrounding your stuff so what you can do to identify why it stopped is output what errors occurs, because it will skip anything where there is an error.
Using exception.Source+","+exception.Message I displayed the error here:
The “Anonymously hosted…” error tells me that one of your invokes has a variable with nothing in it or an out variable is empty.
So, I took a look at your variable/argument structure and it has me thinking that you need to adjust some things there. Like for example, a Main should not have any Out or In arguments, and in your Recursive workflow, you have Out arguments that basically duplicate the In arguments. If you have no intention of changing the value where the Main needs the new value then they should not be Outs or In/Outs.
I don’t know if this will help identify why it’s stopping, but hopefully it will.
Catching the error will help with troubleshooting though.
So, I’m not really that familiar with XMLs but I looked it up and there’s a contains and starts-with function you can use.
many thanks for your suggestions, I think you are really among the most knoledgeable RPA developers in this forum. Concerning your code diagramTree.DocumentElement.SelectNodes("//*[contains(Name(),'Sequence')]", sequenceNamespaceManager), I would like to adjust it to find not those selectors called “sequence” (which is what your code does) but instead those selectors whose DISPLAY NAME contains a certain keyword.
How can I do this? This would really be the key to complete my application.