• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 754
  • Last Modified:

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
0
nstefanov
Asked:
nstefanov
  • 4
  • 3
1 Solution
 
dunglaCommented:
Yes, you need to add xmlns to each element of your XSL file. Xmlns simply are namespace (similar with namespace of .net)
0
 
nstefanovAuthor Commented:
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
0
 
dunglaCommented:
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>
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
nstefanovAuthor Commented:
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
0
 
dunglaCommented:
I see, so you are using typed dataset. Change your typed dataset:

Here is my default dataset xml, this will generate xmlns attribute when you WriteXml:
// dsInventory
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="dsInventory" targetNamespace="http://tempuri.org/dsInventory.xsd" elementFormDefault="qualified"
      attributeFormDefault="qualified" xmlns="http://tempuri.org/dsInventory.xsd" xmlns:mstns="http://tempuri.org/dsInventory.xsd"
      xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
      <xs:element name="dsInventory" msdata:IsDataSet="true">
            <xs:complexType>
                  <xs:choice maxOccurs="unbounded">
                        <xs:element name="Employee">
                              <xs:complexType>
                                    <xs:sequence>
                                          <xs:element name="firstname" type="xs:string" minOccurs="0" />
                                          <xs:element name="lastname" type="xs:string" minOccurs="0" />
                                          <xs:element name="birthdate" type="xs:date" minOccurs="0" />
                                    </xs:sequence>
                              </xs:complexType>
                        </xs:element>
                  </xs:choice>
            </xs:complexType>
      </xs:element>
</xs:schema>

// remove all namespace, this will remove xmlns attribute in root element
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="dsInventory" elementFormDefault="qualified"
      attributeFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
      <xs:element name="dsInventory" msdata:IsDataSet="true">
            <xs:complexType>
                  <xs:choice maxOccurs="unbounded">
                        <xs:element name="Employee">
                              <xs:complexType>
                                    <xs:sequence>
                                          <xs:element name="firstname" type="xs:string" minOccurs="0" />
                                          <xs:element name="lastname" type="xs:string" minOccurs="0" />
                                          <xs:element name="birthdate" type="xs:date" minOccurs="0" />
                                    </xs:sequence>
                              </xs:complexType>
                        </xs:element>
                  </xs:choice>
            </xs:complexType>
      </xs:element>
</xs:schema>
0
 
nstefanovAuthor Commented:
Beautiful thanks so much!

0
 
dunglaCommented:
You are welcome nstefanov
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now