select-xml

Welcome Forums General PowerShell Q&A select-xml

This topic contains 4 replies, has 3 voices, and was last updated by

 
Participant
1 month, 1 week ago.

  • Author
    Posts
  • #122349

    Participant
    Points: 18
    Rank: Member

    for openers, how do I post sample xml to this forum? the "pre" stuff isn't working for me.

  • #122382

    Participant
    Points: 885
    Helping Hand
    Rank: Major Contributor

    easiest way is to use gist

  • #122585

    Participant
    Points: 18
    Rank: Member

    so here is some xml. it's an RDG file from microsoft's Remote Desktop Connection Manager.

    assume $xml = [xml](get-content testrdg.rdg)

    $xml.rdcman.file.group.server.name returns "testserver".

    $xml.selectnode("//rdcman/file/group/server/name") returns nothing
    $xml | select-xml -XPath "//rdcman/file/server/properties/name" returns nothing

    I've read that this has to do with "namespace," and I have to define a namespace. but I don't see a namespace defined in that xml, so I don't know how to decide what namespace to tell powershell to use.

  • #123252

    Participant
    Points: 18
    Rank: Member

    crickets?

  • #123285

    Participant
    Points: 288
    Helping Hand
    Rank: Contributor

    XPath is case-sensitive.

    Using your example XML, these work.

    Select-Xml -Xml $xml -XPath "//RDCMan/file/group/server/properties/name"
    $xml.SelectNodes("//RDCMan/file/group/server/properties/name")

You must be logged in to reply to this topic.