We help IT Professionals succeed at work.

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

343 Views
Last Modified: 2013-11-07
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

Comment
Watch Question

CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
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

Author

Commented:
Thank you Sage.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.