1

I been able in the past to do a similar task but i don't understand why it doesn't work for the this xml. I am using powershell to read iis settings for requestFiltering but when i am searching in the xml the node "fileExtensions" isn't considered a node. here is the xml.

<system.webServer>
  <security>
    <requestFiltering>
      <fileExtensions allowUnlisted="true" applyToWebDAV="true">

        <add fileExtension=".config" allowed="true" />        
      </fileExtensions>
      <requestLimits>
        <headerLimits>
        </headerLimits>
      </requestLimits>
      <verbs allowUnlisted="true" applyToWebDAV="true">
      </verbs>
      <hiddenSegments applyToWebDAV="true">
        <add segment="web.config" />

      </hiddenSegments>
      <alwaysAllowedUrls>
      </alwaysAllowedUrls>
      <alwaysAllowedQueryStrings>
      </alwaysAllowedQueryStrings>
      <denyUrlSequences>
      </denyUrlSequences>
      <denyQueryStringSequences>
      </denyQueryStringSequences>
      <filteringRules>
      </filteringRules>
    </requestFiltering>
  </security>

$val = the above XML:

$xml = [xml]($val)
$node = $xml.SelectSingleNode("//*[local-name() = 'fileExtensions']")

$node is null/ blank. How come?

1 Answer 1

1

What's wrong with using a simpler XPath query:

$node = $xml.SelectSingleNode('//fileExtensions')

FWIW your original query works for me on PowerShell v4.

Sign up to request clarification or add additional context in comments.

1 Comment

Well I copied the other method from some code from the net, i never used this form "//*[local-name() = 'fileExtensions']" but it worked and i stuck with it. But my XPath skills lack. thanks for the update. We are using PS 2.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.