locked
Hangs when parsing large XML RRS feed

  • Question

  • I have a script that scans a folder for XML files and then attempts to parse them, looking for specific nodes.  The script works well with most XML files, but on some of the larger files (100MB+) it hangs seemingly forever.  Is there something I can do to speed up the parsing, or is there a better way to approach this?

    ... [array] $C4P = Get-ChildItem -Path $currentDirectory -filter "fileIndex.xml" -Recurse -Force -ErrorAction SilentlyContinue | Select -expand FullName foreach ($xmlFile in $C4P) {

    #This is where the script hangs for large files [xml] $xmlData = Get-Content $xmlFile ... }



    Friday, May 10, 2019 11:57 AM

Answers

  • I figured as much, but at one point I had left it overnight and it still hadn't completed.  I'm having more success using the following.  It's still a work in progress, and I'm not very familiar with the syntax, but it seems to handle the larger files with more ease.

    ...
    [System.Xml.XmlDocument] $file = new-object System.Xml.XmlDocument
    $file.load($xmlFile)
    $targettedNodes = $file.SelectNodes("ParentNode/ChildNode")
    foreach ($node in $targettedNodes)
    {
      ...
    }


    Friday, May 10, 2019 12:46 PM

All replies

  • Large file can take a very long time to load.  This depends on the system speed and available memory. 


    \_(ツ)_/

    Friday, May 10, 2019 12:41 PM
  • I figured as much, but at one point I had left it overnight and it still hadn't completed.  I'm having more success using the following.  It's still a work in progress, and I'm not very familiar with the syntax, but it seems to handle the larger files with more ease.

    ...
    [System.Xml.XmlDocument] $file = new-object System.Xml.XmlDocument
    $file.load($xmlFile)
    $targettedNodes = $file.SelectNodes("ParentNode/ChildNode")
    foreach ($node in $targettedNodes)
    {
      ...
    }


    Friday, May 10, 2019 12:46 PM
  • Hi,

    I am glad to hear that your issue was successfully resolved. If there is anything else we can do for you, please feel free to post in the forum.

    Best Regards,
    Lee

    Just do it.

    Tuesday, May 14, 2019 9:39 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Friday, May 31, 2019 7:56 AM