Regex for multiple Instances of Tags in XML



I got an xml which i want to parse, heres is an example of it:



<server name="thisServer" dns="...".....>
...
<path>firstPath</path>
<path>secondPath</path>
<path>thirdPath</path>
...
</server>


Now the result should be somehow like:



  • which server

  • got which paths


Example for the pseudocode above:


GrpNo. | Value


1 | thisServer


2 | firstPath


3 | secondPath


4 | thirdPath


this pattern just gives me the last occurence:



<server name="(.*?)".\b[^>]*>.*<path>(.*?)</path>.*</server>


I get all paths using



<server name="(.*?)".\b[^>]*>.*<path>(.*?)</path>.*<path>(.*?)</path>.*<path>(.*?)</path>.*</server>


but that's not the way it should work because I dont know how many paths there may be...


I'm pretty new to this RegEx Stuff and I couldn't find any similar question using the search.


I hope anybody can help me out here :)


No comments:

Post a Comment