collapse whitespace in DataSet.WriteXml() output

G

gerry

There must be a simple way to generate xml from a dataset and have
whitespace collapsed within string elements. I would have thought that this
should be the default behaviour but apparently it isn't.

If I generate the xml as follows :

DataSet ds;
... load data ...
ds.WriteXml("data.xml");
ds.WriteXmlSchema("data.xsd");

I xml I would like to get is :

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<datatab>
<str>abcedf</str>
</datatab>
</NewDataSet>

What I actually get is :

data.xml

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<datatab>
<str>abcedf </str>
</datatab>
</NewDataSet>

data.xsd

<?xml version="1.0" standalone="yes"?>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true"
msdata:Locale="en-CA">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="datatab">
<xs:complexType>
<xs:sequence>
<xs:element name="str" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

if I copy data.xsd to collapseStrings.xsd and modify it as follows :

<?xml version="1.0" standalone="yes"?>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:simpleType name="normalizedString">
<xs:restriction base="xs:string">
<xs:whiteSpace value="collapse" />
</xs:restriction>
</xs:simpleType>
<xs:element name="NewDataSet" msdata:IsDataSet="true"
msdata:Locale="en-CA">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="datatab">
<xs:complexType>
<xs:sequence>
<xs:element name="str"
type="normalizedString" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

and then create the xml using :

DataSet ds;
ds.ReadXmlSchema("collapseStrings.xsd");
... load data ...
ds.WriteXml("data.xml");
ds.WriteXmlSchema("data.xsd");

I now get the following :

data.xml

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<datatab>
<str>abcedf </str>
</datatab>
</NewDataSet>

data.xsd

<?xml version="1.0" standalone="yes"?>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:simpleType name="normalizedString">
<xs:restriction base="xs:string" />
</xs:simpleType>
<xs:element name="NewDataSet" msdata:IsDataSet="true"
msdata:Locale="en-CA">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="datatab">
<xs:complexType>
<xs:sequence>
<xs:element name="str" type="normalizedString"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

note that <xs:whiteSpace value="collapse" /> has been removed from the
schema and the data is not collapsed

I have also tried using the following schemas with no success :

<?xml version="1.0" standalone="yes"?>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:simpleType name="normalizedString">
<xs:restriction base="xs:normalizedString">
<xs:whiteSpace value="collapse" />
</xs:restriction>
</xs:simpleType>
<xs:element name="NewDataSet" msdata:IsDataSet="true"
msdata:Locale="en-CA">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="datatab">
<xs:complexType>
<xs:sequence>
<xs:element name="str"
type="normalizedString" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>


<?xml version="1.0" standalone="yes"?>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true"
msdata:Locale="en-CA">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="datatab">
<xs:complexType>
<xs:sequence>
<xs:element name="str"
type="xs:normalizedString" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

I don't understand why this method doesn't work
I also I think that this is waaaay to complicated for such a simple and i
would suspect common task.

any help with this issue would be greatly appreciated.

gerry
 
K

Kevin Yu

Hi Gerry,

I'm researching on this issue. And I'll update you with new information as
soon as possible.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: "gerry" <[email protected]>
| Subject: collapse whitespace in DataSet.WriteXml() output
| Date: Fri, 12 Sep 2003 03:23:32 -0400
| Lines: 189
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <OiWuY#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: sherbrooke-hse-ppp3604687.sympatico.ca 65.93.161.182
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:60965
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| There must be a simple way to generate xml from a dataset and have
| whitespace collapsed within string elements. I would have thought that
this
| should be the default behaviour but apparently it isn't.
|
| If I generate the xml as follows :
|
| DataSet ds;
| ... load data ...
| ds.WriteXml("data.xml");
| ds.WriteXmlSchema("data.xsd");
|
| I xml I would like to get is :
|
| <?xml version="1.0" standalone="yes"?>
| <NewDataSet>
| <datatab>
| <str>abcedf</str>
| </datatab>
| </NewDataSet>
|
| What I actually get is :
|
| data.xml
|
| <?xml version="1.0" standalone="yes"?>
| <NewDataSet>
| <datatab>
| <str>abcedf </str>
| </datatab>
| </NewDataSet>
|
| data.xsd
|
| <?xml version="1.0" standalone="yes"?>
| <xs:schema id="NewDataSet" xmlns=""
| xmlns:xs="http://www.w3.org/2001/XMLSchema"
| xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
| <xs:element name="NewDataSet" msdata:IsDataSet="true"
| msdata:Locale="en-CA">
| <xs:complexType>
| <xs:choice maxOccurs="unbounded">
| <xs:element name="datatab">
| <xs:complexType>
| <xs:sequence>
| <xs:element name="str" type="xs:string" minOccurs="0" />
| </xs:sequence>
| </xs:complexType>
| </xs:element>
| </xs:choice>
| </xs:complexType>
| </xs:element>
| </xs:schema>
|
| if I copy data.xsd to collapseStrings.xsd and modify it as follows :
|
| <?xml version="1.0" standalone="yes"?>
| <xs:schema id="NewDataSet" xmlns=""
| xmlns:xs="http://www.w3.org/2001/XMLSchema"
| xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
| <xs:simpleType name="normalizedString">
| <xs:restriction base="xs:string">
| <xs:whiteSpace value="collapse" />
| </xs:restriction>
| </xs:simpleType>
| <xs:element name="NewDataSet" msdata:IsDataSet="true"
| msdata:Locale="en-CA">
| <xs:complexType>
| <xs:choice maxOccurs="unbounded">
| <xs:element name="datatab">
| <xs:complexType>
| <xs:sequence>
| <xs:element name="str"
| type="normalizedString" minOccurs="0" />
| </xs:sequence>
| </xs:complexType>
| </xs:element>
| </xs:choice>
| </xs:complexType>
| </xs:element>
| </xs:schema>
|
| and then create the xml using :
|
| DataSet ds;
| ds.ReadXmlSchema("collapseStrings.xsd");
| ... load data ...
| ds.WriteXml("data.xml");
| ds.WriteXmlSchema("data.xsd");
|
| I now get the following :
|
| data.xml
|
| <?xml version="1.0" standalone="yes"?>
| <NewDataSet>
| <datatab>
| <str>abcedf </str>
| </datatab>
| </NewDataSet>
|
| data.xsd
|
| <?xml version="1.0" standalone="yes"?>
| <xs:schema id="NewDataSet" xmlns=""
| xmlns:xs="http://www.w3.org/2001/XMLSchema"
| xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
| <xs:simpleType name="normalizedString">
| <xs:restriction base="xs:string" />
| </xs:simpleType>
| <xs:element name="NewDataSet" msdata:IsDataSet="true"
| msdata:Locale="en-CA">
| <xs:complexType>
| <xs:choice maxOccurs="unbounded">
| <xs:element name="datatab">
| <xs:complexType>
| <xs:sequence>
| <xs:element name="str" type="normalizedString"
| minOccurs="0" />
| </xs:sequence>
| </xs:complexType>
| </xs:element>
| </xs:choice>
| </xs:complexType>
| </xs:element>
| </xs:schema>
|
| note that <xs:whiteSpace value="collapse" /> has been removed from the
| schema and the data is not collapsed
|
| I have also tried using the following schemas with no success :
|
| <?xml version="1.0" standalone="yes"?>
| <xs:schema id="NewDataSet" xmlns=""
| xmlns:xs="http://www.w3.org/2001/XMLSchema"
| xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
| <xs:simpleType name="normalizedString">
| <xs:restriction base="xs:normalizedString">
| <xs:whiteSpace value="collapse" />
| </xs:restriction>
| </xs:simpleType>
| <xs:element name="NewDataSet" msdata:IsDataSet="true"
| msdata:Locale="en-CA">
| <xs:complexType>
| <xs:choice maxOccurs="unbounded">
| <xs:element name="datatab">
| <xs:complexType>
| <xs:sequence>
| <xs:element name="str"
| type="normalizedString" minOccurs="0" />
| </xs:sequence>
| </xs:complexType>
| </xs:element>
| </xs:choice>
| </xs:complexType>
| </xs:element>
| </xs:schema>
|
|
| <?xml version="1.0" standalone="yes"?>
| <xs:schema id="NewDataSet" xmlns=""
| xmlns:xs="http://www.w3.org/2001/XMLSchema"
| xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
| <xs:element name="NewDataSet" msdata:IsDataSet="true"
| msdata:Locale="en-CA">
| <xs:complexType>
| <xs:choice maxOccurs="unbounded">
| <xs:element name="datatab">
| <xs:complexType>
| <xs:sequence>
| <xs:element name="str"
| type="xs:normalizedString" minOccurs="0" />
| </xs:sequence>
| </xs:complexType>
| </xs:element>
| </xs:choice>
| </xs:complexType>
| </xs:element>
| </xs:schema>
|
| I don't understand why this method doesn't work
| I also I think that this is waaaay to complicated for such a simple and i
| would suspect common task.
|
| any help with this issue would be greatly appreciated.
|
| gerry
|
|
|
|
 
K

Kevin Yu

Hi Gerry,

This is a known issue that the DataSet will ignore all the other XSD facet
except MaxLength. The workaround for this issue is to use a
System.Xml.XmlValidatingReader object to validate the XML representation of
the data in a DataSet against its underlying schema.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


--------------------
| From: "gerry" <[email protected]>
| Subject: collapse whitespace in DataSet.WriteXml() output
| Date: Fri, 12 Sep 2003 03:23:32 -0400
| Lines: 189
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <OiWuY#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: sherbrooke-hse-ppp3604687.sympatico.ca 65.93.161.182
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:60965
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| There must be a simple way to generate xml from a dataset and have
| whitespace collapsed within string elements. I would have thought that
this
| should be the default behaviour but apparently it isn't.
|
| If I generate the xml as follows :
|
| DataSet ds;
| ... load data ...
| ds.WriteXml("data.xml");
| ds.WriteXmlSchema("data.xsd");
|
| I xml I would like to get is :
|
| <?xml version="1.0" standalone="yes"?>
| <NewDataSet>
| <datatab>
| <str>abcedf</str>
| </datatab>
| </NewDataSet>
|
| What I actually get is :
|
| data.xml
|
| <?xml version="1.0" standalone="yes"?>
| <NewDataSet>
| <datatab>
| <str>abcedf </str>
| </datatab>
| </NewDataSet>
|
| data.xsd
|
| <?xml version="1.0" standalone="yes"?>
| <xs:schema id="NewDataSet" xmlns=""
| xmlns:xs="http://www.w3.org/2001/XMLSchema"
| xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
| <xs:element name="NewDataSet" msdata:IsDataSet="true"
| msdata:Locale="en-CA">
| <xs:complexType>
| <xs:choice maxOccurs="unbounded">
| <xs:element name="datatab">
| <xs:complexType>
| <xs:sequence>
| <xs:element name="str" type="xs:string" minOccurs="0" />
| </xs:sequence>
| </xs:complexType>
| </xs:element>
| </xs:choice>
| </xs:complexType>
| </xs:element>
| </xs:schema>
|
| if I copy data.xsd to collapseStrings.xsd and modify it as follows :
|
| <?xml version="1.0" standalone="yes"?>
| <xs:schema id="NewDataSet" xmlns=""
| xmlns:xs="http://www.w3.org/2001/XMLSchema"
| xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
| <xs:simpleType name="normalizedString">
| <xs:restriction base="xs:string">
| <xs:whiteSpace value="collapse" />
| </xs:restriction>
| </xs:simpleType>
| <xs:element name="NewDataSet" msdata:IsDataSet="true"
| msdata:Locale="en-CA">
| <xs:complexType>
| <xs:choice maxOccurs="unbounded">
| <xs:element name="datatab">
| <xs:complexType>
| <xs:sequence>
| <xs:element name="str"
| type="normalizedString" minOccurs="0" />
| </xs:sequence>
| </xs:complexType>
| </xs:element>
| </xs:choice>
| </xs:complexType>
| </xs:element>
| </xs:schema>
|
| and then create the xml using :
|
| DataSet ds;
| ds.ReadXmlSchema("collapseStrings.xsd");
| ... load data ...
| ds.WriteXml("data.xml");
| ds.WriteXmlSchema("data.xsd");
|
| I now get the following :
|
| data.xml
|
| <?xml version="1.0" standalone="yes"?>
| <NewDataSet>
| <datatab>
| <str>abcedf </str>
| </datatab>
| </NewDataSet>
|
| data.xsd
|
| <?xml version="1.0" standalone="yes"?>
| <xs:schema id="NewDataSet" xmlns=""
| xmlns:xs="http://www.w3.org/2001/XMLSchema"
| xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
| <xs:simpleType name="normalizedString">
| <xs:restriction base="xs:string" />
| </xs:simpleType>
| <xs:element name="NewDataSet" msdata:IsDataSet="true"
| msdata:Locale="en-CA">
| <xs:complexType>
| <xs:choice maxOccurs="unbounded">
| <xs:element name="datatab">
| <xs:complexType>
| <xs:sequence>
| <xs:element name="str" type="normalizedString"
| minOccurs="0" />
| </xs:sequence>
| </xs:complexType>
| </xs:element>
| </xs:choice>
| </xs:complexType>
| </xs:element>
| </xs:schema>
|
| note that <xs:whiteSpace value="collapse" /> has been removed from the
| schema and the data is not collapsed
|
| I have also tried using the following schemas with no success :
|
| <?xml version="1.0" standalone="yes"?>
| <xs:schema id="NewDataSet" xmlns=""
| xmlns:xs="http://www.w3.org/2001/XMLSchema"
| xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
| <xs:simpleType name="normalizedString">
| <xs:restriction base="xs:normalizedString">
| <xs:whiteSpace value="collapse" />
| </xs:restriction>
| </xs:simpleType>
| <xs:element name="NewDataSet" msdata:IsDataSet="true"
| msdata:Locale="en-CA">
| <xs:complexType>
| <xs:choice maxOccurs="unbounded">
| <xs:element name="datatab">
| <xs:complexType>
| <xs:sequence>
| <xs:element name="str"
| type="normalizedString" minOccurs="0" />
| </xs:sequence>
| </xs:complexType>
| </xs:element>
| </xs:choice>
| </xs:complexType>
| </xs:element>
| </xs:schema>
|
|
| <?xml version="1.0" standalone="yes"?>
| <xs:schema id="NewDataSet" xmlns=""
| xmlns:xs="http://www.w3.org/2001/XMLSchema"
| xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
| <xs:element name="NewDataSet" msdata:IsDataSet="true"
| msdata:Locale="en-CA">
| <xs:complexType>
| <xs:choice maxOccurs="unbounded">
| <xs:element name="datatab">
| <xs:complexType>
| <xs:sequence>
| <xs:element name="str"
| type="xs:normalizedString" minOccurs="0" />
| </xs:sequence>
| </xs:complexType>
| </xs:element>
| </xs:choice>
| </xs:complexType>
| </xs:element>
| </xs:schema>
|
| I don't understand why this method doesn't work
| I also I think that this is waaaay to complicated for such a simple and i
| would suspect common task.
|
| any help with this issue would be greatly appreciated.
|
| gerry
|
|
|
|
 
G

gerry

Hi Kevin - thanks for the info.
I'll have to do some reading up on the XmlValidatingReader to see how it is
used to get the results I am looking for.
I'll post back here if any further info is required.

gerry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top