By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,083 Members | 1,957 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,083 IT Pros & Developers. It's quick & easy.

How to check wellformed xml in Web services

P: 1
Hi,
I am having a webmethod in my web services that accept a xml as string parameter.

[WebMethod]
public bool GetValidXML(string xmlDocument)

Now i want to perform a check againt string xmlDocument that it is in well formed or not?

i used a XMLTextReader that accept input in stream format so to pass my string in xmltextreader i have already converted my string into stream. after it my pain area begin

i cant not use try catch block in web serverices so when i pass null string or <a> it return error but i need only true or false value based on my string if it is in well formed then true otherwise false

my code is


[WebMethod]
public bool GetValidXML(string xmlDocument)
{

ASCIIEncoding myEncoder = new ASCIIEncoding();
byte[] bytes = myEncoder.GetBytes(xmlDocument);
MemoryStream ms = new MemoryStream(bytes);


XmlTextReader reader = new XmlTextReader((Stream)ms);
reader.XmlResolver = null; // ignore the DTD
reader.WhitespaceHandling = WhitespaceHandling.None;

if (reader.Read())
{

//XmlDocument xmlDoc = new XmlDocument();
//xmlDoc.LoadXml(xmlDocument);
//if (xmlDoc.InnerText.ToString().Length > 0)
//{
return true;
}
else
{
return false;
}
}
Apr 27 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.