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
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