XML to DataSet Unique ID

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ken Alexander
    New Member
    • Apr 2009
    • 6

    XML to DataSet Unique ID

    Hello,

    I have a very simple xml file that I am reading into a DataSet using VB.NET. The problem I am having is setting my own unique IDs for the elements. After creating a DataSet of the below XML, a new column is added to each table. In this case Product_ID is not used, but a new column of Product_ID_0 is used. From what I have read I need to use DTD to set this. I tried it as follows and no luck. I would appreciate any help.

    Thank you!

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    
    <!DOCTYPE Products [
    <!ELEMENT Products ( Product+ ) >
    <!ELEMENT Product ( Quantity, ItemNumber, Prompts+ ) >
    <!ELEMENT Quantity (#PCDATA ) >
    <!ELEMENT ItemNumber ( #PCDATA ) >
    <!ATTLIST Product Name CDATA #REQUIRED>
    <!ATTLIST Product Product_ID ID #REQUIRED>
    <!ELEMENT Prompts ( Prompt+ ) >
    <!ATTLIST Prompt Prompts_ID ID #REQUIRED>
    <!ATTLIST Prompt Product_ID IDREF #REQUIRED>
    <!ATTLIST Prompt Name CDATA #REQUIRED>
    <!ATTLIST Prompt Value CDATA #REQUIRED>
    ]>
    
    <Products>
      <Product Name="Product One" Product_ID="1">
        <Quantity>2</Quantity>
        <ItemNumber>1.00</ItemNumber>
        <Prompts>
          <Prompt Prompts_ID="1" Product_ID="1" Name="Finish" Value="Yes" />
          <Prompt Prompts_ID="2" Product_ID="1" Name="Color" Value="Red" />
        </Prompts>
      </Product>
      <Product Name="Product Two" Product_ID="2">
        <Quantity>2</Quantity>
        <ItemNumber>2.00</ItemNumber>
        <Prompts>
          <Prompt Prompts_ID="3" Product_ID="2" Name="Finish" Value="Yes" />
          <Prompt Prompts_ID="4" Product_ID="2" Name="Color" Value="Red" />
        </Prompts>
      </Product>
    </Products>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    a DTD is used to verify whether an XML file conformes to a schema (i.e. if you execute a validating function you get either true or false as result). not more, not less.

    Comment

    • Ken Alexander
      New Member
      • Apr 2009
      • 6

      #3
      Thank you for the response. I guess I misunderstood DTD. How would I set up an XML so that I can specify the ID?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        XML (used to store data) itself can't do that (except XSLT, which is a kind of programming language). You need the script that creates the XML (VB.NET) to take care of that.

        nevertheless, you can use a DTD to verify that the script did use unique IDs.

        Comment

        Working...