How to get properly typed data from xml in Powershell RRS feed

  • Question

  • When i read xml data as objects (dot notation),  the properties of the objects are all [string] while the proper data types are in the <schema>  part of the xml document.

    sample file:

        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xs:element name="doc">
                    <xs:choice maxOccurs="unbounded">
                        <xs:element name="item">
                                    <xs:element name="astring" type="xs:string" minOccurs="0"/>
                                    <xs:element name="along" type="xs:long" minOccurs="0"/>
                                    <xs:element name="adate" type="xs:dateTime" minOccurs="0"/>

    When i do:


    it shows:

    adate                Property              string adate {get;set;}
    along                Property              string along {get;set;}
    astring              Property              string astring {get;set;}

    Is this normal or am i doing something wrong?
    Maybe the question is too simple but i couldn't find an answer in the forum archive.



    • Moved by Bill_Stewart Tuesday, November 7, 2017 9:19 PM Off-topic
    Wednesday, September 6, 2017 9:38 AM

All replies

  • Hi Roel,

    this is working as designed. Xml is understood as a pure string document in PowerShell, because that is how the XML Document type in C# handles it. The only XML it natively converts to types are ...

    • Those imported by Import-Clixml (which usually only works on stuff exported by Export-Clixml)
    • Object types for which conversion was explicitly defined

    You'll probably need to build your own conversion logic or find a solution someone else found and built for it - it's not included out-of-the-box.


    There's no place like

    Wednesday, September 6, 2017 11:28 AM