ianinspain
asked on
Writing an inline schema for my XML which is returned from my web service.
Hi there,
I wonder if anybody can help, i need to return with my XML (from my webservice) an inline schema.
This is because i am using ReadXML in my program which takes the XML and converts to dataset, but currently because there is no inline schema ... all fields are imported as String.
currently this is an example of what is returned, as you can seen the field "TITLES" needs to be a Integer.. which i believe is possible if i specify an inline schema for my XML doc.
<?xml version="1.0" encoding="utf-8" ?>
- <response>
<Error code="0" description="OK" />
- <myData>
- <Record>
<COD>abcdef</COD>
<NAMED>Company A</NAMED>
<TITLES>560</TITLES>
</Record>
- <Record>
<COD>dfggh</COD>
<NAMED>Company B</NAMED>
<TITLES>30000</TITLES>
</Record>
</myData>
</response>
Basically i have created my XML file by simply, building it in a string called returnedXML and then
XmlDocument xmlDocumentObject = new XmlDocument();
xmlDocumentObject.LoadXml( returnedXM L);
But to create an inline schema? How would i go about doing this? Is there some method for creating the schema from XmlDocument object?
Any help would be really appreciated. Thanks in advance
Ian
I wonder if anybody can help, i need to return with my XML (from my webservice) an inline schema.
This is because i am using ReadXML in my program which takes the XML and converts to dataset, but currently because there is no inline schema ... all fields are imported as String.
currently this is an example of what is returned, as you can seen the field "TITLES" needs to be a Integer.. which i believe is possible if i specify an inline schema for my XML doc.
<?xml version="1.0" encoding="utf-8" ?>
- <response>
<Error code="0" description="OK" />
- <myData>
- <Record>
<COD>abcdef</COD>
<NAMED>Company A</NAMED>
<TITLES>560</TITLES>
</Record>
- <Record>
<COD>dfggh</COD>
<NAMED>Company B</NAMED>
<TITLES>30000</TITLES>
</Record>
</myData>
</response>
Basically i have created my XML file by simply, building it in a string called returnedXML and then
XmlDocument xmlDocumentObject = new XmlDocument();
xmlDocumentObject.LoadXml(
But to create an inline schema? How would i go about doing this? Is there some method for creating the schema from XmlDocument object?
Any help would be really appreciated. Thanks in advance
Ian
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Put this code in and run it. You'll see the magic when you look at the WSDL generated and how nice it works on the other side of the wire. Also you'll get near perfect interop with non .NET languages this way. Also the interface nicely.
ASKER
hi devsolns,
i am excited about your answer but i am little but confused...
Are you saying that in my webservice that i should used XMLdocument?
I actually do this
[WebMethod(Description="Re turns test data")]
public XmlDocument Gettestdata(string codCliente)
{
and on the other side i.e.the app that calls the webservice i set the retun type to a xmlNode so i can use xpath to interrogate it
Are you saying i should be doing a different way?
Thanks in advance
Ian
i am excited about your answer but i am little but confused...
Are you saying that in my webservice that i should used XMLdocument?
I actually do this
[WebMethod(Description="Re
public XmlDocument Gettestdata(string codCliente)
{
and on the other side i.e.the app that calls the webservice i set the retun type to a xmlNode so i can use xpath to interrogate it
Are you saying i should be doing a different way?
Thanks in advance
Ian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The problem with returning an XMLDocument type is the user of your service/wsdl has an unknown interface. All its going to say is the return is "some" xml document but i can tell you whats in it hence the reason you wanted to put in an inline schema.
The approach above solves both issues. It provides the exact interface and what elements are included in the Customer object and it also includes the xml schema declaration in the wsdl.
The approach above solves both issues. It provides the exact interface and what elements are included in the Customer object and it also includes the xml schema declaration in the wsdl.
[XmlSchemaProvider("GetCus
[XmlRoot("Customer", Namespace = "http://tempuri.com/Customer/v1")]
public class Customer : IXmlSerializable
{
public string FirstName;
public string LastName;
public DateTime DOB;
public string SSN;
//serialization code.
private static readonly string ns = "http://tempuri.com/Customer/v1";
#region IXmlSerializable Members
public XmlSchema GetSchema()
{
return null;
}
public void ReadXml(XmlReader reader) { }
public void WriteXml(XmlWriter writer)
{
writer.WriteElementString(
writer.WriteElementString(
writer.WriteElementString(
writer.WriteElementString(
}
#endregion
public static XmlQualifiedName GetCustomerSchema(XmlSchem
{
XmlSerializer schemaSerializer = new XmlSerializer(typeof(XmlSc
string xsdPath = "CustomerSchema.xsd";
XmlSchema s = (XmlSchema)schemaSerialize
new XmlTextReader(xsdPath), null);
xs.XmlResolver = new XmlUrlResolver();
xs.Add(s);
return new XmlQualifiedName("Customer
}
}