Link to home
Start Free TrialLog in
Avatar of nstefanov
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
Avatar of dungla
dungla
Flag of Viet Nam image

Yes, you need to add xmlns to each element of your XSL file. Xmlns simply are namespace (similar with namespace of .net)
Avatar of nstefanov
nstefanov

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
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_STRING);
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</FirstName>
    <LastName>Davolio</LastName>
  </Table>
  <Table>
    <FirstName>Andrew</FirstName>
    <LastName>Fuller</LastName>
  </Table>
  <Table>
    <FirstName>Janet</FirstName>
    <LastName>Leverling</LastName>
  </Table>
  <Table>
    <FirstName>Margaret</FirstName>
    <LastName>Peacock</LastName>
  </Table>
  <Table>
    <FirstName>Steven</FirstName>
    <LastName>Buchanan</LastName>
  </Table>
  <Table>
    <FirstName>Michael</FirstName>
    <LastName>Suyama</LastName>
  </Table>
  <Table>
    <FirstName>Robert</FirstName>
    <LastName>King</LastName>
  </Table>
  <Table>
    <FirstName>Laura</FirstName>
    <LastName>Callahan</LastName>
  </Table>
  <Table>
    <FirstName>Anne</FirstName>
    <LastName>Dodsworth</LastName>
  </Table>
</Employees>
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(forXml1);
forXml1.WriteXml(Server.MapPath("/access/Orders.xml")

//result


<?xml version="1.0" standalone="yes"?>
<ForXml xmlns="http://www.tempuri.org/ForXml.xsd">
  <Orders>
    <Oid>6</Oid>
    <OrderDate>2005-04-16T00:00:00.0000000-05:00</OrderDate>
    <OrderTotal>47.54</OrderTotal>
    <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
Avatar of dungla
dungla
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Beautiful thanks so much!

You are welcome nstefanov