Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem with ValidationEventHandler

Konrad
Guest
 
Posts: n/a
#1: Sep 29 '08
Hi
I've got a xml file and xsd with only one namespace -
xmlns:media="http://search.yahoo.com/mrss". When I'm getting the rss
feed for example from Youtube there're also others namespaces such as
xmlns:atom or xmlns:yt. When I'm trying to validate this Xml with my
xsd the validationeventhandler show me only the first error. But what
when we got xml file like:

<channel>
<atom:idIdent </atom:id>
<atom:nameName </atom:name>
.....
</channel>

The Validator show me the atom:id is not in my xsd file but there's
nothing about next wrong items such as atom:name.
What should I do to change this to show me all the errors??

Thanks
kplazinski

Martin Honnen
Guest
 
Posts: n/a
#2: Sep 29 '08

re: Problem with ValidationEventHandler


Konrad wrote:
Quote:
Hi
I've got a xml file and xsd with only one namespace -
xmlns:media="http://search.yahoo.com/mrss". When I'm getting the rss
feed for example from Youtube there're also others namespaces such as
xmlns:atom or xmlns:yt. When I'm trying to validate this Xml with my
xsd the validationeventhandler show me only the first error. But what
when we got xml file like:
>
<channel>
<atom:idIdent </atom:id>
<atom:nameName </atom:name>
....
</channel>
>
The Validator show me the atom:id is not in my xsd file but there's
nothing about next wrong items such as atom:name.
What should I do to change this to show me all the errors??
Can you show us the code you are using to validate the XML?


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Konrad
Guest
 
Posts: n/a
#3: Sep 29 '08

re: Problem with ValidationEventHandler


It's something about this:

protected void Page_Load(object sender, EventArgs e)
{
XmlSchemaSet set = new XmlSchemaSet();
set.Add(null, Server.MapPath("rss.xsd"));
set.Add(null, Server.MapPath("mediarss.xsd"));
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas = set;
settings.ValidationEventHandler += new
ValidationEventHandler(settings_ValidationEventHan dler);
settings.ValidationFlags |=
XmlSchemaValidationFlags.ReportValidationWarnings;
StreamReader sreader = new
StreamReader(Server.MapPath("file.xml"));
XmlReader xreader = XmlReader.Create(sreader, settings);
while (xreader.Read()) { }
}

void settings_ValidationEventHandler(object sender,
ValidationEventArgs e)
{
Response.Write(e.Message + "\r\n");
}

Konrad
Martin Honnen
Guest
 
Posts: n/a
#4: Sep 30 '08

re: Problem with ValidationEventHandler


Konrad wrote:
Quote:
It's something about this:
>
protected void Page_Load(object sender, EventArgs e)
{
XmlSchemaSet set = new XmlSchemaSet();
set.Add(null, Server.MapPath("rss.xsd"));
set.Add(null, Server.MapPath("mediarss.xsd"));
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas = set;
settings.ValidationEventHandler += new
ValidationEventHandler(settings_ValidationEventHan dler);
settings.ValidationFlags |=
XmlSchemaValidationFlags.ReportValidationWarnings;
StreamReader sreader = new
StreamReader(Server.MapPath("file.xml"));
XmlReader xreader = XmlReader.Create(sreader, settings);
while (xreader.Read()) { }
}
>
void settings_ValidationEventHandler(object sender,
ValidationEventArgs e)
{
Response.Write(e.Message + "\r\n");
}
That looks fine to me.
Can you post URLs to the schemas you use and the XML you are trying to
validate? Or post the schemas and the XML itself, but please in a
minimal version to demonstrate the problem.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Closed Thread