nstefanov
asked on
Dataset WriteXml
I am using the WriteXml method to generate an XML doc. The method adds the
xmlns = "http://mywebsiteaddress/myschema.xsd to my root element. I also
have an XSL with a for-each loop that transforms my XML into HTML. If I
manually delete the xmlns section from the XML' root element, the XSL works
and displays fine. With the xmlns section my XSL does not read any of the
data. Do I have to add anything to my XSL or can I disable WriteXml from
adding the xmlns. Thank you very much ahead of time.
Nick
xmlns = "http://mywebsiteaddress/myschema.xsd to my root element. I also
have an XSL with a for-each loop that transforms my XML into HTML. If I
manually delete the xmlns section from the XML' root element, the XSL works
and displays fine. With the xmlns section my XSL does not read any of the
data. Do I have to add anything to my XSL or can I disable WriteXml from
adding the xmlns. Thank you very much ahead of time.
Nick
Yes, you need to add xmlns to each element of your XSL file. Xmlns simply are namespace (similar with namespace of .net)
ASKER
Thanks dungla,
I am trying to do something like this in my xls:
<xsl:for-each select = "Orders">
<xsl:sort select = "Oid"/>
<tr>
<td><xsl:value-of select = "Oid"/></td>
<td><xsl:value-of select = "Uid"/></td>
so I don't have any elements. I can't find another way to specify what namespace these values are. Any other input is appreciated.
Nick
I am trying to do something like this in my xls:
<xsl:for-each select = "Orders">
<xsl:sort select = "Oid"/>
<tr>
<td><xsl:value-of select = "Oid"/></td>
<td><xsl:value-of select = "Uid"/></td>
so I don't have any elements. I can't find another way to specify what namespace these values are. Any other input is appreciated.
Nick
nstefanov,
I have try to create xml file from DataSet via WriteXml method like your. My root element does not contains xmlns attribute. Can you show me the code?.
Here is my example code:
SqlConnection cn = new SqlConnection(CONNECTION_S TRING);
SqlDataAdapter adapter = new SqlDataAdapter(strSql, cn);
DataSet ds = new DataSet();
adapter.Fill(ds);
ds.WriteXml("test.xml");
// result xml
<?xml version="1.0" standalone="yes"?>
<Employees>
<Table>
<FirstName>Nancy</FirstNam e>
<LastName>Davolio</LastNam e>
</Table>
<Table>
<FirstName>Andrew</FirstNa me>
<LastName>Fuller</LastName >
</Table>
<Table>
<FirstName>Janet</FirstNam e>
<LastName>Leverling</LastN ame>
</Table>
<Table>
<FirstName>Margaret</First Name>
<LastName>Peacock</LastNam e>
</Table>
<Table>
<FirstName>Steven</FirstNa me>
<LastName>Buchanan</LastNa me>
</Table>
<Table>
<FirstName>Michael</FirstN ame>
<LastName>Suyama</LastName >
</Table>
<Table>
<FirstName>Robert</FirstNa me>
<LastName>King</LastName>
</Table>
<Table>
<FirstName>Laura</FirstNam e>
<LastName>Callahan</LastNa me>
</Table>
<Table>
<FirstName>Anne</FirstName >
<LastName>Dodsworth</LastN ame>
</Table>
</Employees>
I have try to create xml file from DataSet via WriteXml method like your. My root element does not contains xmlns attribute. Can you show me the code?.
Here is my example code:
SqlConnection cn = new SqlConnection(CONNECTION_S
SqlDataAdapter adapter = new SqlDataAdapter(strSql, cn);
DataSet ds = new DataSet();
adapter.Fill(ds);
ds.WriteXml("test.xml");
// result xml
<?xml version="1.0" standalone="yes"?>
<Employees>
<Table>
<FirstName>Nancy</FirstNam
<LastName>Davolio</LastNam
</Table>
<Table>
<FirstName>Andrew</FirstNa
<LastName>Fuller</LastName
</Table>
<Table>
<FirstName>Janet</FirstNam
<LastName>Leverling</LastN
</Table>
<Table>
<FirstName>Margaret</First
<LastName>Peacock</LastNam
</Table>
<Table>
<FirstName>Steven</FirstNa
<LastName>Buchanan</LastNa
</Table>
<Table>
<FirstName>Michael</FirstN
<LastName>Suyama</LastName
</Table>
<Table>
<FirstName>Robert</FirstNa
<LastName>King</LastName>
</Table>
<Table>
<FirstName>Laura</FirstNam
<LastName>Callahan</LastNa
</Table>
<Table>
<FirstName>Anne</FirstName
<LastName>Dodsworth</LastN
</Table>
</Employees>
ASKER
Sure thanks,
I have a myComponent class which creates all of my connections and then:
I Instantiate my ado data set with this
protected access.ForXml forXml1;
myComponent.FillForXml(for Xml1);
forXml1.WriteXml(Server.Ma pPath("/ac cess/Order s.xml")
//result
<?xml version="1.0" standalone="yes"?>
<ForXml xmlns="http://www.tempuri.org/ForXml.xsd">
<Orders>
<Oid>6</Oid>
<OrderDate>2005-04-16T00:0 0:00.00000 00-05:00</ OrderDate>
<OrderTotal>47.54</OrderTo tal>
<Pid>0131180436</Pid>
<Quantity>1</Quantity>
<Uid>TestUser2</Uid>
<ISBN>0131180436</ISBN>
<price>47.54</price>
<title>C How to Program</title>
<ID>252</ID>
</Orders>
Thanks,
Nick
I have a myComponent class which creates all of my connections and then:
I Instantiate my ado data set with this
protected access.ForXml forXml1;
myComponent.FillForXml(for
forXml1.WriteXml(Server.Ma
//result
<?xml version="1.0" standalone="yes"?>
<ForXml xmlns="http://www.tempuri.org/ForXml.xsd">
<Orders>
<Oid>6</Oid>
<OrderDate>2005-04-16T00:0
<OrderTotal>47.54</OrderTo
<Pid>0131180436</Pid>
<Quantity>1</Quantity>
<Uid>TestUser2</Uid>
<ISBN>0131180436</ISBN>
<price>47.54</price>
<title>C How to Program</title>
<ID>252</ID>
</Orders>
Thanks,
Nick
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Beautiful thanks so much!
You are welcome nstefanov