Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Navigate XML content
Message
 
To
26/08/2008 23:19:37
General information
Forum:
ASP.NET
Category:
XML
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01341375
Message ID:
01344356
Views:
21
>Hi,
>What if I have xml like this
><?xml version="1.0" encoding="utf-8" ?>
><PlugInEvents>
>	<PlugInEvent>
>		<Name>Application.Startup</Name>
>		<Description>Occurred when application startup</Description>
>		<MustImplementTypes>
>			<MustImplementType>
>				<Type>IApplication</Type>
>				<EventHandler>Startup</EventHandler>
>				<Assembly>c:\\aaa.dll</Assembly>
>			</MustImplementType>
>		</MustImplementTypes>
>	</PlugInEvent>
>	<PlugInEvent>
>		<Name>Application.Shutdown</Name>
>		<Description>Occurred when application shutdown</Description>
>		<MustImplementTypes>
>			<MustImplementType>
>				<Type>IApplication</Type>
>				<EventHandler>Shutdown</EventHandler>
>				<Assembly>c:\\aaa.dll</Assembly>
>			</MustImplementType>
>			<MustImplementType>
>				<Type>IGlobal</Type>
>				<EventHandler>GlobalShutdown</EventHandler>
>				<Assembly>c:\\Global.dll</Assembly>
>			</MustImplementType>
>		</MustImplementTypes>
>	</PlugInEvent>
></PlugInEvents>
>And I want to show them like this:-
>
>Name: Application Startup
>Description: Occurred when application startup
>Must Implement:
> Type: IApplication
> EventHandler: Startup
> Assembly: c:\\aaa.dll
>
>Name: Application Shutdown
>Description: Occurred when application shutdown
>Must Implement:
> Type: IApplication
> EventHandler: Shutdown
> Assembly: c:\\aaa.dll
> Type: IGlobal
> EventHandler: GlobalShutdown
> Assembly: c:\\Global.dll
>

Hi, sorry about late reply,
Good question, When DataSet read your XML file, it creates the following 3 tables:
Table: PlugInEvent
Columns: Name, Description, PlugInEvent_Id

Table: MustImplementTypes
Columns: PlugInEvent_Id, MustImplementTypes_Id

Table: MustImplementType
Columns: Type, EventHandler, Assembly, MustImplementTypes_Id
As you see, there are _Id fields which added to each table to keep record relationship between tables.

Surprisingly it creates two DataRelation automatically because of the structure of your XML, with taking
advantage of those relations and loop through tables, you can generate any kind of output which you like.

First DataRelation object: PlugInEvent_MustImplementTypes
Second DataRelation object: MustImplementTypes_MustImplementType

GetChildRows is the method which get related child records from child table.
Let's call your XML file as "xmlNav.xml":
...
            DataSet myXML = new DataSet();
            myXML.ReadXml("xmlNav.xml");

            StringBuilder myXMLstr = new StringBuilder();

            for (int i = 0; i < myXML.Tables[0].Rows.Count; i ++ )
            {
                myXMLstr.Remove(0, myXMLstr.Length - 1);

                DataRow[] myDRowsPIE = myXML.Tables[0].Rows[i].GetChildRows("PlugInEvent_MustImplementTypes");
                myXMLstr.Append( "Name: " + myXML.Tables["PlugInEvent"].Rows[i]["Name"] + "\r\n" +
                    "Description: " + myXML.Tables["PlugInEvent"].Rows[i]["Description"] + "\r\n" +
                    "Must Implement:" + "\r\n" );

                DataRow[] myDRowsMIT = myDRowsPIE[0].GetChildRows("MustImplementTypes_MustImplementType");

                for (int j = 0; j < myDRowsMIT.Length; j++)
                    myXMLstr.Append( "\tType: " + myDRowsMIT[j]["Type"].ToString() + "\r\n" +
                        "\tEventHandler: " + myDRowsMIT[j]["EventHandler"].ToString() + "\r\n" +
                        "\tAssembly: " + myDRowsMIT[j]["Assembly"].ToString() + "\r\n" );

                MessageBox.Show(myXMLstr.ToString());
            }
...
Hope it helps
Previous
Reply
Map
View

Click here to load this message in the networking platform