473,587 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_dat a. 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_ta g>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_ta g>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_dat a(string your_data)
{
StringReader srReaderXML;

try
{
//
// reading the xml doc
//
srReaderXML = new StringReader(yo ur_data);
//
// loading the XML (check for a well-formed doc) and XSD
//
XmlTextReader xtrDocXML = new XmlTextReader(s rReaderXML);
XmlTextReader xtrDocXSD = new XmlTextReader
(ConfigurationS ettings.AppSett ings["XSDPath"].ToString() +
ConfigurationSe ttings.AppSetti ngs["XSDFileNam e"].ToString());
//
// loading the schema (XSD)
//
XmlSchema xsDocXSD = new XmlSchema();
xsDocXSD = XmlSchema.Read( xtrDocXSD,null) ;
XmlSchemaCollec tion xscSchemaColecc ion = new XmlSchemaCollec tion();
xscSchemaColecc ion.Add(xsDocXS D);
//
// validating the XML doc against the XSD
//
XmlValidatingRe ader xvrValidatorDoc XML = new XmlValidatingRe ader
(xtrDocXML);
xvrValidatorDoc XML.Schemas.Add (xscSchemaColec cion);
xvrValidatorDoc XML.ValidationT ype = ValidationType. Schema;
while(xvrValida torDocXML.Read( )); // the exception is thrown here
xvrValidadorDoc XML.Close();

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

Thank you !!
Cesar

Jan 27 '06 #1
2 2992
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_dat a. 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_ta g>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_ta g>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_dat a(string your_data)
{
StringReader srReaderXML;

try
{
//
// reading the xml doc
//
srReaderXML = new StringReader(yo ur_data);
//
// loading the XML (check for a well-formed doc) and XSD
//
XmlTextReader xtrDocXML = new XmlTextReader(s rReaderXML);
XmlTextReader xtrDocXSD = new XmlTextReader
(ConfigurationS ettings.AppSett ings["XSDPath"].ToString() +
ConfigurationSe ttings.AppSetti ngs["XSDFileNam e"].ToString());
//
// loading the schema (XSD)
//
XmlSchema xsDocXSD = new XmlSchema();
xsDocXSD = XmlSchema.Read( xtrDocXSD,null) ;
XmlSchemaCollec tion xscSchemaColecc ion = new XmlSchemaCollec tion();
xscSchemaColecc ion.Add(xsDocXS D);
//
// validating the XML doc against the XSD
//
XmlValidatingRe ader xvrValidatorDoc XML = new XmlValidatingRe ader
(xtrDocXML);
xvrValidatorDoc XML.Schemas.Add (xscSchemaColec cion);
xvrValidatorDoc XML.ValidationT ype = ValidationType. Schema;
while(xvrValida torDocXML.Read( )); // the exception is thrown here
xvrValidadorDoc XML.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_dat a. 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_ta g>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_ta g>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_dat a(string your_data)
{
StringReader srReaderXML;

try
{
//
// reading the xml doc
//
srReaderXML = new StringReader(yo ur_data);
//
// loading the XML (check for a well-formed doc) and XSD
//
XmlTextReader xtrDocXML = new XmlTextReader(s rReaderXML);
XmlTextReader xtrDocXSD = new XmlTextReader
(ConfigurationS ettings.AppSett ings["XSDPath"].ToString() +
ConfigurationSe ttings.AppSetti ngs["XSDFileNam e"].ToString());
//
// loading the schema (XSD)
//
XmlSchema xsDocXSD = new XmlSchema();
xsDocXSD = XmlSchema.Read( xtrDocXSD,null) ;
XmlSchemaCollec tion xscSchemaColecc ion = new XmlSchemaCollec tion();
xscSchemaColecc ion.Add(xsDocXS D);
//
// validating the XML doc against the XSD
//
XmlValidatingRe ader xvrValidatorDoc XML = new XmlValidatingRe ader
(xtrDocXML);
xvrValidatorDoc XML.Schemas.Add (xscSchemaColec cion);
xvrValidatorDoc XML.ValidationT ype = ValidationType. Schema;
while(xvrValida torDocXML.Read( )); // the exception is thrown here
xvrValidadorDoc XML.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
2409
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 is not absolutely wonderful. So what I want to do is to validate it before I upload it. When I try and do this I get MILLIONS of errors (well...
2
1619
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, 913)". That error message is not very user friendly, so I'd like to extract the data in the failing node along with its parent node data, and show that...
5
3589
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 USER EXISTS IN THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED. For this, I used the reference artiicle...
0
1425
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 development and 1 for a staging environment. I'm using an invalid servlet name in the url deliberately in order to test my logic for basic communication...
1
649
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 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....
1
2874
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 schema, I get XML errors (blue squigglies) in a few places, which indicates to me that I should get validation errors while validating through code. ...
3
2318
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 right after the corresponding XmlNode (in the next line) specifying the error message. I am currently validating using an XMLReader with...
5
2424
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 and its clones I encounter a strange problem where I can hear clicking sound non-stop (like the page is being reloaded non- stop), whereas the page...
7
4228
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 XDocument (containing schema xml) against a schema url, it validates successfully..... Has anyone ever seen this before or know why it does this. ...
4
5722
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 all documents referred to in the DTD, and as we have no use for them I want to remove the reference. I'm using XmlReaderSettings to pass in the...
0
7915
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2347
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.