none
Only first object set being read by XML reader RRS feed

  • Question

  • Hello,

    The XML file reads only object group when I use an accompanying XSD file.  

    Without the XSD file all XML object groups are read.

    I have verified this by enumerating the created table and have also done this is c#...so I think I am having an issue with the .net

    Originally there were other datatypes (int ect) but I took them out to test.

    Here is the XSD file:

    <?xml version="1.0" standalone="yes"?>
    <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
      <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
        <xs:complexType>
          <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="Products">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="ProductID" type="xs:string" minOccurs="0" />
                  <xs:element name="ProductName" type="xs:string" minOccurs="0" />
                  <xs:element name="SupplierID" type="xs:string" minOccurs="0" />
                  <xs:element name="CategoryID" type="xs:string" minOccurs="0" />
                  <xs:element name="QuantityPerUnit" type="xs:string" minOccurs="0" />
                  <xs:element name="UnitPrice" type="xs:string" minOccurs="0" />
                  <xs:element name="UnitsInStock" type="xs:string" minOccurs="0" />
                  <xs:element name="UnitsOnOrder" type="xs:string" minOccurs="0" />
                  <xs:element name="ReorderLevel" type="xs:string" minOccurs="0" />
                  <xs:element name="Discontinued" type="xs:string" minOccurs="0" />
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:choice>
        </xs:complexType>
      </xs:element>
    </xs:schema>

    PowerShell

    $dsXml = new-object "System.Data.DataSet" "dsServers"
    $dsXml.ReadXmlSchema('C:\temp\ProdSchema.xsd')
    
    $dsXml.ReadXml("C:\temp\Products1000.XML")
    $xmlProducts = $dsXml.Tables[0]
    
    
    foreach ($Row in $dsXml.Tables[0].Rows)
    { 
      write-host "value is : $($Row[1])"

    XML

    <Products>
      <row>
        <ProductID>1</ProductID>
        <ProductName>Bardudollantor</ProductName>
        <SupplierID>1</SupplierID>
        <CategoryID>1</CategoryID>
        <QuantityPerUnit>plurissimum transit.</QuantityPerUnit>
        <UnitPrice>338.3698</UnitPrice>
        <UnitsInStock>23645</UnitsInStock>
        <UnitsOnOrder>-7654</UnitsOnOrder>
        <ReorderLevel>26584</ReorderLevel>
        <Discontinued>1</Discontinued>
      </row>
        <row>
        <ProductID>4</ProductID>
        <ProductName>4Bardudollantor</ProductName>
        <SupplierID>1</SupplierID>
        <CategoryID>1</CategoryID>
        <QuantityPerUnit>plurissimum transit.</QuantityPerUnit>
        <UnitPrice>338.3698</UnitPrice>
        <UnitsInStock>23645</UnitsInStock>
        <UnitsOnOrder>-7654</UnitsOnOrder>
        <ReorderLevel>26584</ReorderLevel>
        <Discontinued>1</Discontinued>
      </row>
    </Products>


    I am sure I must be misusing the .net elements....

    :)

    Friday, January 23, 2015 6:57 PM

Answers

  • I see now. YOU have no reference to the schema in the datafile.  Adding the reference to the dataset does not tell it how the file is structured.Try it this way:

    $dsXml = new-object "System.Data.DataSet" "dsServers"
    $dsXml.ReadXml("C:\test\Products1000.XML",'InferSchema')
     $dsXml.Tables[0].Rows|ft -auto
    

    This will give you all records.  If you want strong typing reference the schema in the data file or embed the schema in the data file.


    ¯\_(ツ)_/¯

    • Marked as answer by CountryStyle Wednesday, January 28, 2015 12:05 AM
    Friday, January 23, 2015 7:36 PM

All replies

  • It is not clear what your question is.


    ¯\_(ツ)_/¯

    Friday, January 23, 2015 7:23 PM
  • I see now. YOU have no reference to the schema in the datafile.  Adding the reference to the dataset does not tell it how the file is structured.Try it this way:

    $dsXml = new-object "System.Data.DataSet" "dsServers"
    $dsXml.ReadXml("C:\test\Products1000.XML",'InferSchema')
     $dsXml.Tables[0].Rows|ft -auto
    

    This will give you all records.  If you want strong typing reference the schema in the data file or embed the schema in the data file.


    ¯\_(ツ)_/¯

    • Marked as answer by CountryStyle Wednesday, January 28, 2015 12:05 AM
    Friday, January 23, 2015 7:36 PM
  • Ah....OK, thanks....will have to see about fixing the XML....I would like the datatype in there.


    Friday, January 23, 2015 8:21 PM
  • I see now. YOU have no reference to the schema in the datafile.  Adding the reference to the dataset does not tell it how the file is structured.Try it this way:

    $dsXml = new-object "System.Data.DataSet" "dsServers"
    $dsXml.ReadXml("C:\test\Products1000.XML",'InferSchema')
     $dsXml.Tables[0].Rows|ft -auto

    This will give you all records.  If you want strong typing reference the schema in the data file or embed the schema in the data file.


    ¯\_(ツ)_/¯

    This works for basic xml documents...thanks....will post again for complex......the tables don't load like I expected.

    Wednesday, January 28, 2015 12:05 AM