Problem with ValidationEventHandler

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Konrad

    Problem with ValidationEventHandler

    Hi
    I've got a xml file and xsd with only one namespace -
    xmlns:media="ht tp://search.yahoo.co m/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 validationevent handler show me only the first error. But what
    when we got xml file like:

    <channel>
    <atom:idIdent </atom:id>
    <atom:nameNam e </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

    #2
    Re: Problem with ValidationEvent Handler

    Konrad wrote:
    Hi
    I've got a xml file and xsd with only one namespace -
    xmlns:media="ht tp://search.yahoo.co m/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 validationevent handler show me only the first error. But what
    when we got xml file like:
    >
    <channel>
    <atom:idIdent </atom:id>
    <atom:nameNam e </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

    Comment

    • Konrad

      #3
      Re: Problem with ValidationEvent Handler

      It's something about this:

      protected void Page_Load(objec t sender, EventArgs e)
      {
      XmlSchemaSet set = new XmlSchemaSet();
      set.Add(null, Server.MapPath( "rss.xsd")) ;
      set.Add(null, Server.MapPath( "mediarss.xsd") );
      XmlReaderSettin gs settings = new XmlReaderSettin gs();
      settings.Valida tionType = ValidationType. Schema;
      settings.Schema s = set;
      settings.Valida tionEventHandle r += new
      ValidationEvent Handler(setting s_ValidationEve ntHandler);
      settings.Valida tionFlags |=
      XmlSchemaValida tionFlags.Repor tValidationWarn ings;
      StreamReader sreader = new
      StreamReader(Se rver.MapPath("f ile.xml"));
      XmlReader xreader = XmlReader.Creat e(sreader, settings);
      while (xreader.Read() ) { }
      }

      void settings_Valida tionEventHandle r(object sender,
      ValidationEvent Args e)
      {
      Response.Write( e.Message + "\r\n");
      }

      Konrad

      Comment

      • Martin Honnen

        #4
        Re: Problem with ValidationEvent Handler

        Konrad wrote:
        It's something about this:
        >
        protected void Page_Load(objec t sender, EventArgs e)
        {
        XmlSchemaSet set = new XmlSchemaSet();
        set.Add(null, Server.MapPath( "rss.xsd")) ;
        set.Add(null, Server.MapPath( "mediarss.xsd") );
        XmlReaderSettin gs settings = new XmlReaderSettin gs();
        settings.Valida tionType = ValidationType. Schema;
        settings.Schema s = set;
        settings.Valida tionEventHandle r += new
        ValidationEvent Handler(setting s_ValidationEve ntHandler);
        settings.Valida tionFlags |=
        XmlSchemaValida tionFlags.Repor tValidationWarn ings;
        StreamReader sreader = new
        StreamReader(Se rver.MapPath("f ile.xml"));
        XmlReader xreader = XmlReader.Creat e(sreader, settings);
        while (xreader.Read() ) { }
        }
        >
        void settings_Valida tionEventHandle r(object sender,
        ValidationEvent Args 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

        Comment

        Working...