Connecting Tech Pros Worldwide Help | Site Map

XML to DataSet Unique ID

Newbie
 
Join Date: Apr 2009
Posts: 6
#1: Apr 27 '09
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!

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <!DOCTYPE Products [
  5. <!ELEMENT Products ( Product+ ) >
  6. <!ELEMENT Product ( Quantity, ItemNumber, Prompts+ ) >
  7. <!ELEMENT Quantity (#PCDATA ) >
  8. <!ELEMENT ItemNumber ( #PCDATA ) >
  9. <!ATTLIST Product Name CDATA #REQUIRED>
  10. <!ATTLIST Product Product_ID ID #REQUIRED>
  11. <!ELEMENT Prompts ( Prompt+ ) >
  12. <!ATTLIST Prompt Prompts_ID ID #REQUIRED>
  13. <!ATTLIST Prompt Product_ID IDREF #REQUIRED>
  14. <!ATTLIST Prompt Name CDATA #REQUIRED>
  15. <!ATTLIST Prompt Value CDATA #REQUIRED>
  16. ]>
  17.  
  18. <Products>
  19.   <Product Name="Product One" Product_ID="1">
  20.     <Quantity>2</Quantity>
  21.     <ItemNumber>1.00</ItemNumber>
  22.     <Prompts>
  23.       <Prompt Prompts_ID="1" Product_ID="1" Name="Finish" Value="Yes" />
  24.       <Prompt Prompts_ID="2" Product_ID="1" Name="Color" Value="Red" />
  25.     </Prompts>
  26.   </Product>
  27.   <Product Name="Product Two" Product_ID="2">
  28.     <Quantity>2</Quantity>
  29.     <ItemNumber>2.00</ItemNumber>
  30.     <Prompts>
  31.       <Prompt Prompts_ID="3" Product_ID="2" Name="Finish" Value="Yes" />
  32.       <Prompt Prompts_ID="4" Product_ID="2" Name="Color" Value="Red" />
  33.     </Prompts>
  34.   </Product>
  35. </Products>
  36.  
  37.  
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,642
#2: Apr 28 '09

re: XML to DataSet Unique ID


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.
Newbie
 
Join Date: Apr 2009
Posts: 6
#3: Apr 28 '09

re: XML to DataSet Unique ID


Thank you for the response. I guess I misunderstood DTD. How would I set up an XML so that I can specify the ID?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,642
#4: Apr 28 '09

re: XML to DataSet Unique ID


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.
Reply