Ok, the mapping schema is as under:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ht="http://www.w3.org/1999/xhtml" xmlns:cus="http://localhost/"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema"
targetNamespace="http://localhost/" elementFormDefault="qualified"
attributeFormDefault="unqualified" >
<xs:element name="template">
<xs:complexType>
<xs:sequence>
<xs:element name="PatientDetails1" type="cus:FullNameBlock"
sql:relation="PatientDetails"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="FullNameBlock">
<xs:sequence>
<xs:element name="Name" type="cus:NameBlock" sql:relation="PatientName">
<xs:annotation>
<xs:appinfo>
<sql:relationship parent="PatientDetails" parent-key="PDName"
child="PatientName" child-key="ID" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="NameBlock">
<xs:sequence>
<xs:element name="FirstName" type="xs:string" sql:field="PDNFirstName" />
<xs:element name="LastName" type="xs:string" sql:field="PDNLastName" />
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
</xs:schema>
I am trying to xpath query the above schema using the following code:
try{
SqlXmlCommand cmd;
FileStream f;
string conString = "Provider=SQLOLEDB;Data
Source='(local)';database=TestRep; Integrated Security=SSPI";
cmd = new SqlXmlCommand(conString);
cmd.Namespaces = "xmlns:x='http://localhost/'";
cmd.CommandType = SqlXmlCommandType.XPath;
cmd.CommandText = "x:PatientDetails1";
cmd.SchemaPath = " F:\\Testing\\XML\\CustomSchema\\CustomSc
hema4.xsd";
f = new FileStream("F:\\Testing\\XML\\CustomList3.xml", FileMode.Create);
cmd.ExecuteToStream(f);
f.Close() ;
}
catch(Exception ex)
{
string temp = ex.Message;
MessageBox.Show(temp);
}
}
when I run the above mentioned code it throws the following exception:
SqlXmlException
Message="Schema: relationship expected on 'PatientDetails1'."
"Rainabba" wrote:
> Sounds like you want to look at using is-mapped="false", but you didn't gi
ve
> enough detail for me to be sure what you're doing. You can only have one
> "root" node so mapping it at all should typically throw an error unless
> you're using limit-field/limit-value to ensure you have only one row
> returning to map. If that doesn't help, be sure to reply with the exceptio
n
> and a copy of the schema throwing it.
> rainabba
> "Ahsan" <Ahsan@.discussions.microsoft.com> wrote in message
> news:9640E9E3-78A8-4CFB-8388-5377CC81A283@.microsoft.com...
> database
> schema
>Could you please try again with putting sql:is-constant='1' on the root
element (the element named as 'template' in your below schema) you don't
want to map?
Bertan ARI
This posting is provided "AS IS" with no warranties, and confers no rights.
"Ahsan" <Ahsan@.discussions.microsoft.com> wrote in message
news:A2C7C59D-5C67-4B9D-AF8B-6BF11FBA0C3B@.microsoft.com...
> Ok, the mapping schema is as under:
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:ht="http://www.w3.org/1999/xhtml" xmlns:cus="http://localhost/"
> xmlns:sql="urn:schemas-microsoft-com:mapping-schema"
> targetNamespace="http://localhost/" elementFormDefault="qualified"
> attributeFormDefault="unqualified" >
> <xs:element name="template">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="PatientDetails1" type="cus:FullNameBlock"
> sql:relation="PatientDetails"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:complexType name="FullNameBlock">
> <xs:sequence>
> <xs:element name="Name" type="cus:NameBlock" sql:relation="PatientName">
> <xs:annotation>
> <xs:appinfo>
> <sql:relationship parent="PatientDetails" parent-key="PDName"
> child="PatientName" child-key="ID" />
> </xs:appinfo>
> </xs:annotation>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> <xs:complexType name="NameBlock">
> <xs:sequence>
> <xs:element name="FirstName" type="xs:string" sql:field="PDNFirstName" />
> <xs:element name="LastName" type="xs:string" sql:field="PDNLastName" />
> </xs:sequence>
> <xs:attribute name="id" type="xs:ID"/>
> </xs:complexType>
> </xs:schema>
> I am trying to xpath query the above schema using the following code:
>
> try{
> SqlXmlCommand cmd;
> FileStream f;
> string conString = "Provider=SQLOLEDB;Data
> Source='(local)';database=TestRep; Integrated Security=SSPI";
> cmd = new SqlXmlCommand(conString);
> cmd.Namespaces = "xmlns:x='http://localhost/'";
> cmd.CommandType = SqlXmlCommandType.XPath;
> cmd.CommandText = "x:PatientDetails1";
> cmd.SchemaPath = " F:\\Testing\\XML\\CustomSchema\\CustomSc
hema4.xsd";
> f = new FileStream("F:\\Testing\\XML\\CustomList3.xml", FileMode.Create);
> cmd.ExecuteToStream(f);
> f.Close() ;
> }
> catch(Exception ex)
> {
> string temp = ex.Message;
> MessageBox.Show(temp);
> }
> }
> when I run the above mentioned code it throws the following exception:
> SqlXmlException
> Message="Schema: relationship expected on 'PatientDetails1'."
> "Rainabba" wrote:
>
>
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment