469,939 Members | 2,409 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,939 developers. It's quick & easy.

Strange error validating XML against XSD

Hello,

I've developed a .NET C# web service; which has one method named, let's say,
upload_your_data. This method has one parameter ( string your_data). The
value that this parameter will actually have is the content of a XML
document. This data will be processed and check for a well-formed xml
document and will be validated against a XSD. Before putting my code, let me
go on and explain the whole situation.

This web method is invoked by some guys outside my organization and they are
using java applications (jsp's … it seems to be).
I've tested my web method locally (intranet) from the test page (the one
with the "invoke" button) and works fine. Also, I have tested my web service
using a .NET Windows App which loads a XML file and invokes the web method to
upload the content of the file and works perfectly. Moreover I tested the web
service with this windows app from my home connected to the internet via my
ISP and invoking the web method directly from my company's web server. This
test was also completed successfully.
And, if this is not enough testing, I enabled the httpget and httppost
methods to enable the web method to be tested remotely using the test page.
I've done this with some of my friends.

However these guys from this other company, have a java application which
invokes my web method and it fails exactly when the XSD is performed. It
throws this error: The data at the root level is invalid. Line 1, position 1.

If, for example the content of the XML is simply:

<?xml version="1.0" encoding="UTF-8"?><my_root_tag>this is my
name</my_root_tag>

I receive exactly that string (I check the value of the web method's
parameter: your_data, which is a string variable) when testing the web method
with my testing apps. But when these guys invoke the method, the value that I
get from them is:

<?xml version="1.0" encoding="UTF-8"?><my_root_tag>this is my
name;</my_root_tag>

Instead of the first one (the one that you can read "normally"). And not to
mention the characters for all the "special" Spanish letters that will appear
when more tags are present.
What can be wrong? Is it me or they ? The one responsible for receiving or
sending the context is such way. I don't know how they generate the xml
document, whether it's stored on a database or loaded from a physical file.
These guys say that I'm not applying the "right encoding" to the data that
they're sending; but fail to answer me which one they're using.

Please help.

This is my web methods code:

[WebMethod]
public string upload_your_data(string your_data)
{
StringReader srReaderXML;

try
{
//
// reading the xml doc
//
srReaderXML = new StringReader(your_data);
//
// loading the XML (check for a well-formed doc) and XSD
//
XmlTextReader xtrDocXML = new XmlTextReader(srReaderXML);
XmlTextReader xtrDocXSD = new XmlTextReader
(ConfigurationSettings.AppSettings["XSDPath"].ToString() +
ConfigurationSettings.AppSettings["XSDFileName"].ToString());
//
// loading the schema (XSD)
//
XmlSchema xsDocXSD = new XmlSchema();
xsDocXSD = XmlSchema.Read(xtrDocXSD,null);
XmlSchemaCollection xscSchemaColeccion = new XmlSchemaCollection();
xscSchemaColeccion.Add(xsDocXSD);
//
// validating the XML doc against the XSD
//
XmlValidatingReader xvrValidatorDocXML = new XmlValidatingReader
(xtrDocXML);
xvrValidatorDocXML.Schemas.Add(xscSchemaColeccion) ;
xvrValidatorDocXML.ValidationType = ValidationType.Schema;
while(xvrValidatorDocXML.Read()); // the exception is thrown here
xvrValidadorDocXML.Close();

return "this is right"
}
catch(Exception ex)
{
return "this is wrong + ex.Message;
}
}

Thank you !!
Cesar

Jan 27 '06 #1
2 2790
I think they may be sending you a null terminated string.
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Cesar" wrote:
Hello,

I've developed a .NET C# web service; which has one method named, let's say,
upload_your_data. This method has one parameter ( string your_data). The
value that this parameter will actually have is the content of a XML
document. This data will be processed and check for a well-formed xml
document and will be validated against a XSD. Before putting my code, let me
go on and explain the whole situation.

This web method is invoked by some guys outside my organization and they are
using java applications (jsp's … it seems to be).
I've tested my web method locally (intranet) from the test page (the one
with the "invoke" button) and works fine. Also, I have tested my web service
using a .NET Windows App which loads a XML file and invokes the web method to
upload the content of the file and works perfectly. Moreover I tested the web
service with this windows app from my home connected to the internet via my
ISP and invoking the web method directly from my company's web server. This
test was also completed successfully.
And, if this is not enough testing, I enabled the httpget and httppost
methods to enable the web method to be tested remotely using the test page.
I've done this with some of my friends.

However these guys from this other company, have a java application which
invokes my web method and it fails exactly when the XSD is performed. It
throws this error: The data at the root level is invalid. Line 1, position 1.

If, for example the content of the XML is simply:

<?xml version="1.0" encoding="UTF-8"?><my_root_tag>this is my
name</my_root_tag>

I receive exactly that string (I check the value of the web method's
parameter: your_data, which is a string variable) when testing the web method
with my testing apps. But when these guys invoke the method, the value that I
get from them is:

<?xml version="1.0" encoding="UTF-8"?><my_root_tag>this is my
name;</my_root_tag>

Instead of the first one (the one that you can read "normally"). And not to
mention the characters for all the "special" Spanish letters that will appear
when more tags are present.
What can be wrong? Is it me or they ? The one responsible for receiving or
sending the context is such way. I don't know how they generate the xml
document, whether it's stored on a database or loaded from a physical file.
These guys say that I'm not applying the "right encoding" to the data that
they're sending; but fail to answer me which one they're using.

Please help.

This is my web methods code:

[WebMethod]
public string upload_your_data(string your_data)
{
StringReader srReaderXML;

try
{
//
// reading the xml doc
//
srReaderXML = new StringReader(your_data);
//
// loading the XML (check for a well-formed doc) and XSD
//
XmlTextReader xtrDocXML = new XmlTextReader(srReaderXML);
XmlTextReader xtrDocXSD = new XmlTextReader
(ConfigurationSettings.AppSettings["XSDPath"].ToString() +
ConfigurationSettings.AppSettings["XSDFileName"].ToString());
//
// loading the schema (XSD)
//
XmlSchema xsDocXSD = new XmlSchema();
xsDocXSD = XmlSchema.Read(xtrDocXSD,null);
XmlSchemaCollection xscSchemaColeccion = new XmlSchemaCollection();
xscSchemaColeccion.Add(xsDocXSD);
//
// validating the XML doc against the XSD
//
XmlValidatingReader xvrValidatorDocXML = new XmlValidatingReader
(xtrDocXML);
xvrValidatorDocXML.Schemas.Add(xscSchemaColeccion) ;
xvrValidatorDocXML.ValidationType = ValidationType.Schema;
while(xvrValidatorDocXML.Read()); // the exception is thrown here
xvrValidadorDocXML.Close();

return "this is right"
}
catch(Exception ex)
{
return "this is wrong + ex.Message;
}
}

Thank you !!
Cesar

Jan 29 '06 #2
Hi Dale,

Sorry, event the post was "displayed right".
What I received from them (those guys) are those coded characters that were
used in the early days of the internet. For instance:
Instead of getting the < symbol I receive "& l t;" (without the blank
spaces), instead of getting the > symbol I receive "& g t;"
So what I receive from them is something like (without the blank spaces):

?& l t;xml version=& quot;1.0& quot; encoding=& quot;UTF-8& quot;?& g t& l
t;my_root_tag& g t;this is my name;& g t& l t;/my_root_tag& g t;

Cesar

"Dale" wrote:
I think they may be sending you a null terminated string.
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Cesar" wrote:
Hello,

I've developed a .NET C# web service; which has one method named, let's say,
upload_your_data. This method has one parameter ( string your_data). The
value that this parameter will actually have is the content of a XML
document. This data will be processed and check for a well-formed xml
document and will be validated against a XSD. Before putting my code, let me
go on and explain the whole situation.

This web method is invoked by some guys outside my organization and they are
using java applications (jsp's … it seems to be).
I've tested my web method locally (intranet) from the test page (the one
with the "invoke" button) and works fine. Also, I have tested my web service
using a .NET Windows App which loads a XML file and invokes the web method to
upload the content of the file and works perfectly. Moreover I tested the web
service with this windows app from my home connected to the internet via my
ISP and invoking the web method directly from my company's web server. This
test was also completed successfully.
And, if this is not enough testing, I enabled the httpget and httppost
methods to enable the web method to be tested remotely using the test page.
I've done this with some of my friends.

However these guys from this other company, have a java application which
invokes my web method and it fails exactly when the XSD is performed. It
throws this error: The data at the root level is invalid. Line 1, position 1.

If, for example the content of the XML is simply:

<?xml version="1.0" encoding="UTF-8"?><my_root_tag>this is my
name</my_root_tag>

I receive exactly that string (I check the value of the web method's
parameter: your_data, which is a string variable) when testing the web method
with my testing apps. But when these guys invoke the method, the value that I
get from them is:

<?xml version="1.0" encoding="UTF-8"?><my_root_tag>this is my
name;</my_root_tag>

Instead of the first one (the one that you can read "normally"). And not to
mention the characters for all the "special" Spanish letters that will appear
when more tags are present.
What can be wrong? Is it me or they ? The one responsible for receiving or
sending the context is such way. I don't know how they generate the xml
document, whether it's stored on a database or loaded from a physical file.
These guys say that I'm not applying the "right encoding" to the data that
they're sending; but fail to answer me which one they're using.

Please help.

This is my web methods code:

[WebMethod]
public string upload_your_data(string your_data)
{
StringReader srReaderXML;

try
{
//
// reading the xml doc
//
srReaderXML = new StringReader(your_data);
//
// loading the XML (check for a well-formed doc) and XSD
//
XmlTextReader xtrDocXML = new XmlTextReader(srReaderXML);
XmlTextReader xtrDocXSD = new XmlTextReader
(ConfigurationSettings.AppSettings["XSDPath"].ToString() +
ConfigurationSettings.AppSettings["XSDFileName"].ToString());
//
// loading the schema (XSD)
//
XmlSchema xsDocXSD = new XmlSchema();
xsDocXSD = XmlSchema.Read(xtrDocXSD,null);
XmlSchemaCollection xscSchemaColeccion = new XmlSchemaCollection();
xscSchemaColeccion.Add(xsDocXSD);
//
// validating the XML doc against the XSD
//
XmlValidatingReader xvrValidatorDocXML = new XmlValidatingReader
(xtrDocXML);
xvrValidatorDocXML.Schemas.Add(xscSchemaColeccion) ;
xvrValidatorDocXML.ValidationType = ValidationType.Schema;
while(xvrValidatorDocXML.Read()); // the exception is thrown here
xvrValidadorDocXML.Close();

return "this is right"
}
catch(Exception ex)
{
return "this is wrong + ex.Message;
}
}

Thank you !!
Cesar

Jan 29 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Iain | last post: by
3 posts views Thread by Martin Eckart | last post: by
7 posts views Thread by =?Utf-8?B?Q29kZVJhem9y?= | last post: by
4 posts views Thread by agda.karlberg | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.