locked
select-xml and selectnode RRS feed

  • Question

  • I'm opening an RDG file from Remote Desktop Connection Manager 2.7. it's an xml file. I see no references to any namespaces in it. but select-xml and selectnode are not returning any data.

    <?xml version="1.0" encoding="utf-8"?>
    <RDCMan programVersion="2.7" schemaVersion="3">
      <file>
        <credentialsProfiles />
        <properties>
          <expanded>True</expanded>
          <name>testrdg</name>
        </properties>
        <server>
          <properties>
            <name>test</name>
          </properties>
        </server>
      </file>
      <connected />
      <favorites />
      <recentlyUsed />
    </RDCMan>

    there's the xml file. I have this saved as the variable $rdgxml, and

    $rdgxml.rdcman.file.server.properties.name

    successfully returns the word "test."

    but neither of the following return anything:

    $rdgxml|Select-Xml-XPath"//rdcman/file/server/properties/name"


    $rdgxml.SelectNodes("//rdcman/file/server/properties/name")

    I keep reading that this is about an xml namespace. but I have no idea how to fix it. how do I define a namespace?



    • Edited by John_Curtiss Wednesday, November 7, 2018 2:21 AM
    Wednesday, November 7, 2018 2:18 AM

All replies

  • PS > [xml]$xml = @'
    <?xml version="1.0" encoding="utf-8"?>
    <RDCMan programVersion="2.7" schemaVersion="3">
      <file>
        <credentialsProfiles />
        <properties>
          <expanded>True</expanded>
          <name>testrdg</name>
        </properties>
        <server>
          <properties>
            <name>test</name>
          </properties>
        </server>
      </file>
      <connected />
      <favorites />
      <recentlyUsed />
    </RDCMan>
    '@
    PS > $$xml.SelectSingleNode('//server/properties/name').'#text'
    testrdg

    Works for me.

    $xmltxt = @'
    <?xml version="1.0" encoding="utf-8"?>
    <RDCMan programVersion="2.7" schemaVersion="3">
      <file>
        <credentialsProfiles />
        <properties>
          <expanded>True</expanded>
          <name>testrdg</name>
        </properties>
        <server>
          <properties>
            <name>test</name>
          </properties>
        </server>
      </file>
      <connected />
      <favorites />
      <recentlyUsed />
    </RDCMan>
    '@
    
    $xmltxt | Select-Xml -XPath '//rdcman/file/server/properties/name'
    $xmltxt | Select-Xml -XPath '//RDCMan/file/server/properties/name'|select -expand node
    ([xml]$xmltxt).SelectSingleNode('//RDCMan/file/server/properties/name')
    All XML is case sensitive.  "rdcman" will not work.  "RDCMan" is correct case.


    \_(ツ)_/



    Wednesday, November 7, 2018 2: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.

    Tuesday, November 27, 2018 2:20 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.

    Tuesday, December 4, 2018 2:38 AM