Avatar of ClassicCPLus
ClassicCPLus
 asked on

Data.DataSet.ReadXml not returning all records on my XML file

I am only getting one record:
Question: How do you get all the records?
Sub Question: Is there a better way to approach loading a table in the dataset?
Here is my code:
I want to populate a dataset from an xml file that looks like this: 
 
<?xml version="1.0" encoding="utf-8" ?>
<NewDataset xmlns="http://tempuri.org/TransactionCodes.xsd">
     <Transaction> 
      <Code>DPO</Code>
      <Value>DPO - EXTERNAL VENDOR/EMPLOYEE REIMBURSEMENT</Value>
    </Transaction>
    <Transaction>
      <Code>DPO</Code>
      <Value>DPO - INTERDEPARMENTAL</Value>
    </Transaction>
    <Transaction>
      <Code>AD</Code>
      <Value>AD - CHECK</Value>
    </Transaction>
    <Transaction>
      <Code>CR</Code>
      <Value>CR - CASH RECEIPT</Value>
    </Transaction>
    <Transaction>
      <Code>CX</Code>
      <Value>CX - CANCELLED CHECK</Value>
    </Transaction>
    <Transaction>
      <Code>EB</Code>
      <Value>EB - EXPENSE BUDGET</Value>
    </Transaction>
    <Transaction>
      <Code>ET</Code>
      <Value>ET - EXPENSE BUDGET TRANSFER - CUFS</Value>
    </Transaction>  
    <Transaction>
      <Code>IN</Code>
      <Value>IN - INVOICE EXTERNAL BILLING</Value>
     </Transaction>  
    <Transaction>
      <Code>IV</Code>
      <Value>IV - INTRA INSTITUTION VOUCHER(REVENUE)</Value>
    </Transaction>
     <Transaction>
       <Code>IX</Code>
       <Value>IX - INTRA INSTITUTION VOUCHER(EXPENSE)</Value>
   </Transaction>
    <Transaction>
      <Code>JV</Code>
      <Value>JV - JOURNAL VOUCHER</Value>
   </Transaction>
   <Transaction>
     <Code>MW</Code>
     <Value>MW - MANUAL WARRANT</Value>
   </Transaction>
    <Transaction>
      <Code>PC</Code>
      <Value>PC - PURCHASE ORDER COMMODITY</Value>
    </Transaction>
    <Transaction>
      <Code>PO</Code>
      <Value>PO - NON-COMMODITY PURCHASE ORDER - ADVANTAGE</Value>
    </Transaction>
    <Transaction>
      <Code>PV</Code>
      <Value>PV - PAYMENT VOUCHER</Value>
    </Transaction>
    <Transaction>
      <Code>RB</Code>
      <Value>RB - REVENUE BUDGET</Value>
    </Transaction> 
    <Transaction>
      <Code>RQ</Code>
      <Value>RQ - REQUISITION</Value>
    </Transaction> 
    <Transaction>
      <Code>RX</Code>
      <Value>RX - REQUISITION COMMODITY</Value>
    </Transaction>  
    <Transaction>
      <Code>SC</Code>
      <Value>SC - NON-COMMODITY PURCHASE ORDER - ADVANTAGE</Value>
    </Transaction>
    <Transaction>
      <Code>TA</Code>
      <Value>TA - TRAVEL ADVANCE CUFS</Value>
    </Transaction>
    <Transaction>
      <Code>TB</Code>
      <Value>TB - EXPENSE BUDGET TRANSFER - ADVANTAGE</Value>
    </Transaction>
    <Transaction>
      <Code>TC</Code>
      <Value>TC - TRAVEL CHECK</Value>
    </Transaction>
      <Code>TE</Code>
      <Value>TE - TRAVEL ADVANCE -ADVANTAGE</Value>
    <Transaction>
      <Code>TP</Code>
      <Value>TP - TRAVEL PAYMENT</Value>
    </Transaction> 
    <Transaction>
      <Code>TV</Code>
      <Value>TV - TRANSFER VOUCHER</Value>
    </Transaction>  
   
</NewDataset>
            
The schema looks like this:
 
 
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://tempuri.org/TransactionCodes.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="NewDataset">
    <xs:complexType>
      <xs:sequence>
        <xs:choice maxOccurs="unbounded">
          <xs:element maxOccurs="unbounded" name="Transaction">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="Code" type="xs:string" />
                <xs:element name="Value" type="xs:string" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
          <xs:element name="Code" type="xs:string" />
          <xs:element name="Value" type="xs:string" />
        </xs:choice>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
 
 
Here is my code:
        Dim ds As New Data.DataSet()
 
        Dim mypath As String = Server.MapPath("TransactionCodes.xml") 'think do not need this line 
        ds.ReadXml((Server.MapPath("TransactionCodes.xml")))
        Dim myView As Data.DataView
        myView = ds.Tables(0).DefaultView
        Me.GridView1.DataSource = ds
        Me.GridView1.DataBind()
 
I am only getting one record:
NewDataset_Id Code Value 
0 	     TE   TE - TRAVEL ADVANCE -ADVANTAGE

Open in new window

.NET ProgrammingVisual Basic.NETC#

Avatar of undefined
Last Comment
ClassicCPLus

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Wayne Taylor (webtubbs)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
rachitkohli

Yes the open/close tag is missing for one of the element, i just checked out.. After having proper open/close, it worked properly.
Additionally , why are you setting the datasource to dataset, since you have dataview
This can be replaced with
Me.GridView1.DataSource = myView

XMl file should be like this

<?xml version="1.0" encoding="utf-8" ?>
<NewDataset xmlns="http://tempuri.org/TransactionCodes.xsd">
  <Transaction>
    <Code>DPO</Code>
    <Value>DPO - EXTERNAL VENDOR/EMPLOYEE REIMBURSEMENT</Value>
  </Transaction>
  <Transaction>
    <Code>DPO</Code>
    <Value>DPO - INTERDEPARMENTAL</Value>
  </Transaction>
  <Transaction>
    <Code>AD</Code>
    <Value>AD - CHECK</Value>
  </Transaction>
  <Transaction>
    <Code>CR</Code>
    <Value>CR - CASH RECEIPT</Value>
  </Transaction>
  <Transaction>
    <Code>CX</Code>
    <Value>CX - CANCELLED CHECK</Value>
  </Transaction>
  <Transaction>
    <Code>EB</Code>
    <Value>EB - EXPENSE BUDGET</Value>
  </Transaction>
  <Transaction>
    <Code>ET</Code>
    <Value>ET - EXPENSE BUDGET TRANSFER - CUFS</Value>
  </Transaction>
  <Transaction>
    <Code>IN</Code>
    <Value>IN - INVOICE EXTERNAL BILLING</Value>
  </Transaction>
  <Transaction>
    <Code>IV</Code>
    <Value>IV - INTRA INSTITUTION VOUCHER(REVENUE)</Value>
  </Transaction>
  <Transaction>
    <Code>IX</Code>
    <Value>IX - INTRA INSTITUTION VOUCHER(EXPENSE)</Value>
  </Transaction>
  <Transaction>
    <Code>JV</Code>
    <Value>JV - JOURNAL VOUCHER</Value>
  </Transaction>
  <Transaction>
    <Code>MW</Code>
    <Value>MW - MANUAL WARRANT</Value>
  </Transaction>
  <Transaction>
    <Code>PC</Code>
    <Value>PC - PURCHASE ORDER COMMODITY</Value>
  </Transaction>
  <Transaction>
    <Code>PO</Code>
    <Value>PO - NON-COMMODITY PURCHASE ORDER - ADVANTAGE</Value>
  </Transaction>
  <Transaction>
    <Code>PV</Code>
    <Value>PV - PAYMENT VOUCHER</Value>
  </Transaction>
  <Transaction>
    <Code>RB</Code>
    <Value>RB - REVENUE BUDGET</Value>
  </Transaction>
  <Transaction>
    <Code>RQ</Code>
    <Value>RQ - REQUISITION</Value>
  </Transaction>
  <Transaction>
    <Code>RX</Code>
    <Value>RX - REQUISITION COMMODITY</Value>
  </Transaction>
  <Transaction>
    <Code>SC</Code>
    <Value>SC - NON-COMMODITY PURCHASE ORDER - ADVANTAGE</Value>
  </Transaction>
  <Transaction>
    <Code>TA</Code>
    <Value>TA - TRAVEL ADVANCE CUFS</Value>
  </Transaction>
  <Transaction>
    <Code>TB</Code>
    <Value>TB - EXPENSE BUDGET TRANSFER - ADVANTAGE</Value>
  </Transaction>
  <Transaction>
    <Code>TC</Code>
    <Value>TC - TRAVEL CHECK</Value>
  </Transaction>
  <Transaction>
  <Code>TE</Code>
  <Value>TE - TRAVEL ADVANCE -ADVANTAGE</Value>
  </Transaction>
  <Transaction>
    <Code>TP</Code>
    <Value>TP - TRAVEL PAYMENT</Value>
  </Transaction>
  <Transaction>
    <Code>TV</Code>
    <Value>TV - TRANSFER VOUCHER</Value>
  </Transaction>
 
</NewDataset>

Open in new window

ClassicCPLus

ASKER
Thank you Sage.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy