CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2005
    Posts
    159

    Question How to use datarelations after reading xml

    All,

    when I read this xml using DataSet.ReadXml I get a dataset with relations. How can I use this data inside when the relations have an autogenerated name? In the end I would like to put the 'Value' fields in a String[], how can I do this?

    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <Types>
    	<Type>
    		<Type>Discrete</Type>
    		<Name>bool</Name>
    		<ID>1</ID>
    		<Minimum>False</Minimum>
    		<Maximum>True</Maximum>
    		<Value>False</Value>
    		<Value>True</Value>
    	</Type>
    </Types>
    Thanks,
    Jef

  2. #2
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: How to use datarelations after reading xml

    Jef,

    Not sure I totally understand, lets start with this code (very hard-coded to your specific XML example) and see how we can improve it. Or, can you post what you have tried so far....
    Code:
    DataSet ds = new DataSet();
    ds.ReadXml(@"C:\test.xml");
    
    Int32 numRows = ds.Tables["Value"].Rows.Count;
    
    String[] s = new String[numRows];
    
    for (Int32 i = 0; i < numRows; i++)
        s[i] = ds.Tables["Value"].Rows[i][0].ToString();
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  3. #3
    Join Date
    Nov 2005
    Posts
    159

    Re: How to use datarelations after reading xml

    Ok, my example was maybe a bit too vague to explain my problem completely. Suppose the xml looks like this:

    Code:
    <Types>
    	<Type>
    		<Type>Discrete</Type>
    		<Name>bool</Name>
    		<ID>1</ID>
    		<Minimum>False</Minimum>
    		<Maximum>True</Maximum>
    		<Value>False</Value>
    		<Value>True</Value>
    	</Type>
    	<Type>
    		<Type>Discrete</Type>
    		<Name>Status</Name>
    		<ID>2</ID>
    		<Minimum>Not available</Minimum>
    		<Maximum>Defined</Maximum>
    		<Value>Not available</Value>
    		<Value>Available</Value>
                            <Value>Not defined</Value>
                            <Value>Defined</Value>
    	</Type>
    </Types>
    In the end I want to add this data to a class containing a String[] values. For the first object this array should contain False and True, for the second one not available, available, not defined and defined. Your example won't do the trick in this example. I will need to do something with the table relations but I don't know how.

    thank you,
    Jef

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

Featured