473,378 Members | 1,066 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 2978
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Iain | last post by:
I've got a system which takes an XML file, translates it into an update gram and then loads it into my database with SQLXML3 (all in dot net). But it's fragile. And the SQLXML 3 error reporting...
2
by: Joakim Olesen | last post by:
Hello When validating xml against a schema, the most frequent error I get is something like "The 'FOO' attribute has an invalid value according to its data type. An error occurred at , (25,...
5
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This is used for comparing a value enterd by the user against the primary key in the SQL database. IF the VALUE ENTERED BY THE...
0
by: Mark | last post by:
I have a very strange problem that is driving me nuts. My application is using the webclient object to send data to a webserver running on a unix box. We use 2 different environments, 1 for...
1
by: Cesar | last post by:
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...
1
by: Chris Lieb | last post by:
I have an XML Schema file that I know is correct becuase I currently use it in a VB6 program to validate XML documents. Also, if I load an XML file into VS2005 that is not valid against this...
3
by: Martin Eckart | last post by:
Hi guys, I have an XML Schema and I am validation many XML files against the schema. If successful, the files get transferred to another location. If not, then I would like to add an error tag...
5
by: ioni | last post by:
Good day, fellows! I have a strange problem – at my site there is a flash strip, that loads data dynamically. It works fine (grabs data from the remote server and presents it), however in IE7...
7
by: =?Utf-8?B?Q29kZVJhem9y?= | last post by:
I wrote a method to validate and xml file against a schema. If the file does not conform to the schema, it throws an error. It works fine except for one curious thing. If I try to validate an...
4
by: agda.karlberg | last post by:
Hello, I need to remove the DTD reference from an xml document, the reason for this is that we want to validate against a schema instead (which we have locally). It takes up to a minute to fetch...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.