Kamii47

I have a xml < xml version="1.0" >
<Amazonbooks>
<Mybook>
<MyBooktitle>Astronomy</title>
<booknumber>b121</booknumber>
<city>SHILLINGTON</city>
<state>PA</state>
<description>Astronomy b121 Description on 19 dec</description>
</Mybook>
<Mybook>
<MyBooktitle>Geology</title>
<booknumber>b212</booknumber>
<city>West Palm Beach</city>
<state>FL</state>
<description>Geology b212 Description on 19 dec</description>
</Mybook>
<Mybook>
<MyBooktitle>Astrology </title>
<booknumber>b313</booknumber>
<city>SHIPPENSBURG</city>
<state>PA</state>
<country>US</country>
<description>Astrology b313 Description on 20 dec</description>
</Mybook>
</Amazonbooks>

I wants it to be loaded into the dataset with Amazonbooks table name as Books
Mybook as Book and MyBooktitle as BookTitle.booknumber as BookCode
How can I do that
What I really want's is to load this xml into one dataset say DSXML and records from the db into another dataset let say DSSQL.
Then compare the records.{records compared on
booknumber which is in db as bookcode}
1, Those records which are in the xml but not in the sql should be deleted.
2, Then those records with
.booknumber which are both in the DSXML and DSSQL these records data from dsxml would be updated
3,Then in last those records {booknumbers}which are in xml but not in db are inserted into the db.

If there is any similar type of sample then please help me
thanks







Re: XML and the .NET Framework How to rename xml node name and load into dataset

Martin Honnen

An XSLT stylesheet like below can do the necessary transformation. You can run an XSLT transformation with System.Xml.Xsl.XslTransform in .NET 1.x and System.Xml.Xsl.XslCompiledTransform in .NET 2.0.

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="xml" indent="no"/>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="Amazonbooks">
<Books>
<xsl:apply-templates select="@* | node()"/>
</Books>
</xsl:template>

<xsl:template match="Mybook">
<Book>
<xsl:apply-templates select="@* | node()"/>
</Book>
</xsl:template>

<xsl:template match="MyBooktitle">
<BookTitle>
<xsl:apply-templates select="@* | node()"/>
</BookTitle>
</xsl:template>

<xsl:template match="booknumber">
<BookCode>
<xsl:apply-templates select="@* | node()"/>
</BookCode>
</xsl:template>

</xsl:stylesheet>






Re: XML and the .NET Framework How to rename xml node name and load into dataset

Kamii47

Thanks a lot Martin Honnen .I got it.

Now please can you guide me for my data mainupulation problem.

That is after loading data into the datasets how can I acieve the things which I have mentioned.

Thanks






Re: XML and the .NET Framework How to rename xml node name and load into dataset

Kamii47

I can't able to transform then my xml file according to given xsl then load it into the dataset.

Can anybody help






Re: XML and the .NET Framework How to rename xml node name and load into dataset

Kamii47

Thanks All

I have solve the problem by by following code

Stream msOutput;

XPathDocument doc = new XPathDocument(@"c:\MyXMLFile.xml");

XslTransform xslt = new XslTransform();

xslt.Load(@"c:\MyXMLFile.xsl");

msOutput = new MemoryStream();

xslt.Transform(doc,null,msOutput);

msOutput.Flush();

msOutput.Position = 0;

DataSet ds = new DataSet();

ds.ReadXml(msOutput);

doc = null;

xslt =null;

msOutput = null;

PrintDataSet(ds); //check is transformation change my columns

InsertIntoDB( ds,"1");

I have to ask 3 questions

1, One problem i am getting is that while compiling i am getting obeselte method warning at line xslt.Transform(doc,null,msOutput);

2,Can I add some more column in xslt whihc are not in xml file.{I want's some default value associated with these column}

3,Can I use CSV file in place of xml file as some of my source file could be in csv files

Please help me in these






Re: XML and the .NET Framework How to rename xml node name and load into dataset

Sergey Dubinets - MSFT

1. In .NET 2.0 use XslCompiledTransform.

2. Yes.

3. Yes. Pass to Transform() instance of XmlCsvReader: http://msdn2.microsoft.com/en-us/library/aa302293.aspx