Results 1 to 4 of 4

Thread: [RESOLVED] Dataset readxml - read only certain elements(columns)

  1. #1

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Resolved [RESOLVED] Dataset readxml - read only certain elements(columns)

    Hi guys

    Dataset's ReadXML() method would read an XML document. But how would we skip certain columns ?

    For example:
    Code:
    <product>
      <book>
        <id>1</id>
        <name>abc1</name>
        <price>Rs. 100</price>
      </book>
      <book>
        <id>2</id>
        <name>abc2</name>
        <price>Rs. 250</price>
      </book>
      <book>
        <id>3</id>
        <name>aaasd</name>
        <price>Rs. 12345</price>
      </book>
    </product>
    So, if I use ReadXML(), it would read the whole document and the dataTable would have "id" column, "name" column and "price" column.

    But I want to have only "id" and "name" column. How can I skip certain columns from reading it ?

    Thanks

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  2. #2

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Dataset readxml - read only certain elements(columns)

    Next time I should spend a few minutes experimenting before posting the question in here. Because I found the solution after spending 15 minutes of experiments.

    Solution:
    vb.net Code:
    1. '~~~ ds is the DataSet that reads the XML document. It's 0th indexed DataTable is the actual table that contains the data. So, we could call the RemoveAt() or Remove() method to remove the unwanted columns...!
    2.  
    3. ds.Tables(0).Columns.RemoveAt(3) '~~~ index of column to be removed is 3

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3
    Hyperactive Member Ram2Curious's Avatar
    Join Date
    Apr 2010
    Posts
    484

    Re: [RESOLVED] Dataset readxml - read only certain elements(columns)

    This is not fair Akki. Provide an opportunity for someone else to resolve the thread.

  4. #4

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: [RESOLVED] Dataset readxml - read only certain elements(columns)

    Quote Originally Posted by Ram2Curious View Post
    This is not fair Akki. Provide an opportunity for someone else to resolve the thread.


    Also found that, there's no need of using a DataSet. Only DataTable is needed as it has both the ReadXML() and WriteXML() methods. Previously, I was thinking that, those methods were available only in a DataSet.

    Another thing that I found is, when using WriteXML() method, we have to use a 2nd parameter called "XmlWriteMode.WriteSchema" to write the schema in the XML file. Otherwise, when we try to read this XML file(which we have created), VB would pop an error message saying it couldn't harness the schema.


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width