I'm gonna have to try it.
Bear in mind that I am NOT looking for a general solution: I KNOW that I
have no before content and I can control my namespace if need be - and I've
already transformed my input from some more general XML to the subset of the
dialect which SQLXML likes.
I'll let you know as and when and if I get anywhere!
Thanks!
Iain
"Christoph Schittko [MVP]" <ch********************@austin.rr.com> wrote in
message news:eJ**************@TK2MSFTNGP10.phx.gbl...
If you were to add a definition for a ROOT element to the schema then that
ROOT element would belong to the
http://DOD.COM/Disks namespace. I seem to
remember that updategrams work regardless what namespace the ROOT element
belongs to because an updategram is a specialized case of a SQLXML template.
I am not sure about this though. It's for you to try that out. ;)
You you need to define the root type to have zero or more <before><after>
groups :
<schema targetNamespace="urn:schemas-microsoft-com:mapping-schema"
xmlns="http://www.w3.org/2001/XMLSchema">
<complexType name="updgType">
<sequence minOccurs="0" maxOccurs="unbounded">
<element name="before" type="beforeType" minOccurs="0" maxOccurs="1"/>
<element name="after" type="afterType" minOccurs="0" maxOccurs="1"/>
<sequence>
</complexType>
<complexType name="beforeType">
<sequence>
<any /> <!-- no validation possible -->
</sequence>
</complexType>
<complexType name="afterType">
<sequence>
<any /> <!-- no validation possible -->
</sequence>
<attribute name="returnid" type="string" />
</complexType>
</schema>
<schema xmlns:disk="http://DOD.COM/Disks"
targetNamespace="http://DOD.COM/Disks"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<element name="ROOT" type="sql:updgType" />
That's the first problem solved, but now it gets harder. You need to define
the content the ROOT element. You could go with the types I dummied up in my
previous post but the benefits of validating against that schema are
marginal. You ensure that the ROOT element has groups of <before><after>
elements, where either one of them can be optional. You are not able to
validate the content inside the <before> or <after> elements because the
urn:schemas-microsoft-com:mapping-schema namespace cannot know anything
about any application specific schemas and has to define both types as
completely open:
<element name="before">
<complexType>
<sequence>
<any namespace="##any" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
You can't "forward declare" elements and types like you can in programming
languages like C++. Even of you tried to define your own custom schema for
the urn:schemas-microsoft-com:mapping-schema namespace that only your
application uses to validate updategrams like this:
<element name="before">
<complexType>
<sequence>
<any namespace="http://DOD.COM/Disks" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
I don't believe you couldn't solve that problem. You would introduce a
circular dependency and if I read the XML Schema spec [0] right then this is
not allowed.
The id, at-identity and guid attributes pose another probem. Updategrams
define the to propagating automatically generated @@IDENTITY values You can
define them in an attributeGroup in the schema for the mapping schema
namespace:
<attributeGroup>
<attribute name="id" type="int" />
<attribute name="at-identity" type="string" />
<attribute name="guid" type="string" />
</attributeGroup>
However, these attributes need to occur on the elements in the XML that you
are inserting. Therefore you need to CHANGE(!) your application's schema to
make these attributes schema legal on every element where you need expect
them to let SQLXML know about @@IDENTITY values. Remember though, that this
is probably pointless, since you probably can't build a schema that will
validate the types from your schema because of the circular reference
problem.
Regardless how you order the two schemas, you will always have a circular
reference problem. The mapping-schema schema needs to know about your
application's schema's namespace to enable validation of the content of the
<before> and <after> element and the application's schema needs to know
about the attributeGroup for inserting into tables with @@IDENTITY columns.
Avoiding the circular reference with wildcard content renders a schema will
not allow reasonable validation of updategrams.
I hope this post makes sense.
--
HTH
Christoph Schittko [MVP, XmlInsider]
Software Architect, .NET Mentor