|
| Hi Experts:
I'd like to export SQL Server 2000 data to an XML file using SQLXML with the
following schema:
====================
====================
============
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="LeaseAdded_Simple"
targetNamespace="http://tempuri.org/Simple.xsd"
elementFormDefault="qualified" xmlns="http://tempuri.org/Simple.xsd"
xmlns:mstns="http://tempuri.org/Simple.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Document">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="SimpleTable">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:string" minOccurs="0" />
<xs:element name="Name" type="xs:string" minOccurs="0" />
<xs:element name="Date" type="xs:dateTime" />
<xs:element name="Type" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
====================
====================
============
The code is as followed:
====================
====================
=============
try
{
StringBuilder strBuilder = new StringBuilder();
strBuilder.Append("SELECT ID, Name, Date, Type FROM dbo.SimpleTable");
SqlXmlCommand xmlCommand = new
SqlXmlCommand(@" Provider=SQLOLEDB;Se
rver=SQL2000;databas
e=TestDB;Integrated
Security=SSPI;");
xmlCommand.ClientSideXml = true;
xmlCommand.RootTag = "SimpleRecord";
xmlCommand.SchemaPath = @"Simple.xsd";
xmlCommand.CommandType = SqlXmlCommandType.XPath;
xmlCommand.CommandText = strBuilder.ToString();
Stream reader = xmlCommand.ExecuteStream();
FileStream fsOut = File.Create("SimpleOutput.xml");
StreamWriter sw = new StreamWriter(fsOut);
using (StreamReader sr = new StreamReader(reader)
)
{
sw.Write(sr.ReadToEnd());
}
sw.Flush();
sw.Close();
fsOut.Close();
}
catch (Exception exception)
{
Console.WriteLine(exception.ToString());
}
====================
====================
=============
However, an error occurred when the code is executed with this message:
Microsoft.Data.SqlXml.SqlXmlException: MSXML: is an invalid or unsupported
XPath ---> System.Runtime.InteropServices.COMException (0x80040E14): MSXML:
is an invalid or unsupported XPath
at
Microsoft.Data.SqlXml.Common.UnsafeNativeMethods. ISQLXMLCommandManage
dInterface. ExecuteToOutputStrea
m()
at Microsoft.Data.SqlXml.SqlXmlCommand.innerExecute(Stream strm)
Would you tell me what I did wrong?
Thanks,
Tom
|
|