1

I have some very big XML files with

<Frequency>14400</Frequency> 

It can be anywhere in files, because all files have different schema, so I can't search with pre-defined XPath.

All I need is to find all nodes with Frequency <= 14400 and show XPath to it

Good example is code I copy here, but instead of PATH I need XPath.

Any solutions?

Get-ChildItem -Recurse |
    Select-String -Pattern ">60<" |
    group Path |
    select Name
c:\temp\xml.xml :::: /ManagementPack/Monitoring/Discoveries/Discovery/DataSource/Frequency 60
c:\temp\xml2.xml :::: /ManagementPack/Monitoring/Discoveries/Discovery/DataSource/Frequency 100
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Igor Kuznetsov
  • 421
  • 1
  • 6
  • 15
  • I've created [a more robust version](https://stackoverflow.com/a/58443084/45375) of the - elegant, but limited - function in the accepted answer to the linked question. XPath 3 apparently offers a built-in function but at least currently .NET doesn't seem to support that: see [this answer](https://stackoverflow.com/a/31627712/45375). – mklement0 Oct 18 '19 at 02:30

1 Answers1

2

How about using local-name XPATH function?

This ignores the namespace, so it will work with any XML. Using this technique, you dont need to look for XPATH from the element (which is not straightforward).

Apply to your code:

[xml]$xml = Get-Content ("<some_path>")
$result = $xml.SelectSingleNode("//*[local-name()='Frequency' and number(text()) <= 1440]")
EylM
  • 5,967
  • 2
  • 16
  • 28