Click here to Skip to main content
15,881,588 members
Home / Discussions / XML / XSL
   

XML / XSL

 
GeneralRe: Getting XML content Pin
stevenykl1-Jun-11 0:21
stevenykl1-Jun-11 0:21 
QuestionHelp to write Xquery Pin
Neno9930-Apr-11 3:37
Neno9930-Apr-11 3:37 
AnswerRe: Help to write Xquery Pin
jschell30-Apr-11 12:57
jschell30-Apr-11 12:57 
GeneralRe: Help to write Xquery Pin
Neno993-May-11 16:07
Neno993-May-11 16:07 
GeneralRe: Help to write Xquery Pin
Richard MacCutchan3-May-11 21:58
mveRichard MacCutchan3-May-11 21:58 
GeneralRe: Help to write Xquery Pin
jschell4-May-11 8:47
jschell4-May-11 8:47 
QuestionHow to bind the data into a class object from a list. Pin
Rocky2329-Apr-11 0:57
Rocky2329-Apr-11 0:57 
AnswerRe: How to bind the data into a class object from a list. Pin
jschell29-Apr-11 9:47
jschell29-Apr-11 9:47 
QuestionXML Search Pin
DJ24526-Apr-11 20:49
DJ24526-Apr-11 20:49 
AnswerRe: XML Search Pin
GregStevens6-Jul-11 15:43
GregStevens6-Jul-11 15:43 
QuestionXpath syntax. Pin
Mel Padden4-Apr-11 22:34
Mel Padden4-Apr-11 22:34 
AnswerRe: Xpath syntax. Pin
Tarun.K.S4-Apr-11 23:40
Tarun.K.S4-Apr-11 23:40 
GeneralRe: Xpath syntax. Pin
Mel Padden5-Apr-11 0:06
Mel Padden5-Apr-11 0:06 
QuestionHelp to make condition in xsd file Pin
MrKBA30-Mar-11 22:41
MrKBA30-Mar-11 22:41 
AnswerRe: Help to make condition in xsd file Pin
RugbyLeague19-Apr-11 2:26
RugbyLeague19-Apr-11 2:26 
Questionattribute restriction [modified] [Solved] Pin
V.24-Mar-11 22:40
professionalV.24-Mar-11 22:40 
I wrote a small .Net app that validates an XML with an XSD.
It looks like it is working, until I did the following below.

the XML is validated although the attribute is restricted to 8 chars.
What could I be doing wrong?

many thanks.

[Solved]
like this:
public static void Validate(string xml_file, string xsd_file, string xmlnamespace){
    schemaexception = null;
    validationexception = null;
    XmlReader reader  = null;
    XmlReaderSettings xmlreadersettings = new XmlReaderSettings();
    XmlSchemaSet myschema = new XmlSchemaSet();
    try{
        xmlreadersettings.Schemas.Add(xmlnamespace, xsd_file);
        xmlreadersettings.ValidationType = ValidationType.Schema;
        xmlreadersettings.ValidationEventHandler += new ValidationEventHandler(xmlreadersettings_ValidationEventHandler);
        reader = XmlReader.Create(xml_file, xmlreadersettings);
        while(reader.Read());
    }                                               //end try
    catch (XmlException XmlExp){
        schemaexception = XmlExp;
    }                                               //end catch
    catch(XmlSchemaException XmlSchExp){
        schemaexception = XmlSchExp;
    }                                               //end catch
    catch(Exception GenExp){
        schemaexception = GenExp;
    }                                               //end catch
    finally{
        reader.Close();
    }                                               //end finally
}

[/Solved]

[EDIT]I found an online tool dat also validates the xml against the xsd and that seems to work. it even says what the exact error is. I'll have to have a look at the .Net code. If anyone has a good article about it, let me know. (I'll also, of course, search for myself)[/EDIT]

xml
<MyCode value="abcdefSSSgh"/>


xsd
<xs:element name="MyCode" minOccurs="1">
  <xs:complexType>
    <xs:attribute name="value" use="required">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:length value="8"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:complexType>
</xs:element>


.Net code
public static Exception Validate(string xml_file, string xsd_file, string xmlnamespace){
    Exception xmlexception = null;
    XmlReader reader  = null;
    XmlSchemaSet myschema = new XmlSchemaSet();
    try{
        reader = XmlReader.Create(xml_file);
        myschema.Add(xmlnamespace, xsd_file);
        reader.Settings.Schemas.Add(myschema);
        while (reader.Read());
    }                                               //end try
    catch (XmlException XmlExp){
        xmlexception = XmlExp;
    }                                               //end catch
    catch(XmlSchemaException XmlSchExp){
        xmlexception = XmlSchExp;
    }                                               //end catch
    catch(Exception GenExp){
        xmlexception = GenExp;
    }                                               //end catch
    finally{
        reader.Close();
    }
    return xmlexception;

V.
modified on Friday, March 25, 2011 6:07 AM

QuestionVisual Studio's XSD vs Liquid Technologies Code Generator Pin
Ger Hayden16-Mar-11 4:40
Ger Hayden16-Mar-11 4:40 
Questionusing search web service Pin
ekaup11-Mar-11 23:36
ekaup11-Mar-11 23:36 
AnswerRe: using search web service Pin
jschell13-Mar-11 10:16
jschell13-Mar-11 10:16 
GeneralRe: using search web service Pin
ekaup13-Mar-11 12:22
ekaup13-Mar-11 12:22 
QuestionHow limitate the attribute of the root to it? Pin
Pierre besquent24-Feb-11 22:06
Pierre besquent24-Feb-11 22:06 
AnswerRe: How limitate the attribute of the root to it? Pin
dasblinkenlight9-Mar-11 2:20
dasblinkenlight9-Mar-11 2:20 
QuestionIs Serialization worth it? Pin
Ger Hayden21-Feb-11 23:47
Ger Hayden21-Feb-11 23:47 
Questiongenerate xml based on schema. Pin
Ramkumar_S16-Feb-11 15:33
Ramkumar_S16-Feb-11 15:33 
AnswerRe: generate xml based on schema. Pin
Ger Hayden22-Feb-11 0:04
Ger Hayden22-Feb-11 0:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.