Click here to Skip to main content
14,430,522 members
   

XML / XSL

 
QuestionXML Search Pin
DJ24526-Apr-11 21:49
MemberDJ24526-Apr-11 21:49 
AnswerRe: XML Search Pin
GregStevens6-Jul-11 16:43
MemberGregStevens6-Jul-11 16:43 
QuestionXpath syntax. Pin
Mel Padden4-Apr-11 23:34
MemberMel Padden4-Apr-11 23:34 
AnswerRe: Xpath syntax. Pin
Tarun.K.S5-Apr-11 0:40
MemberTarun.K.S5-Apr-11 0:40 
GeneralRe: Xpath syntax. Pin
Mel Padden5-Apr-11 1:06
MemberMel Padden5-Apr-11 1:06 
QuestionHelp to make condition in xsd file Pin
MrKBA30-Mar-11 23:41
MemberMrKBA30-Mar-11 23:41 
AnswerRe: Help to make condition in xsd file Pin
RugbyLeague19-Apr-11 3:26
MemberRugbyLeague19-Apr-11 3:26 
Questionattribute restriction [modified] [Solved] Pin
V.24-Mar-11 23:40
professionalV.24-Mar-11 23: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 5:40
MemberGer Hayden16-Mar-11 5:40 
Questionusing search web service Pin
ekaup12-Mar-11 0:36
Memberekaup12-Mar-11 0:36 
AnswerRe: using search web service Pin
jschell13-Mar-11 11:16
Memberjschell13-Mar-11 11:16 
GeneralRe: using search web service Pin
ekaup13-Mar-11 13:22
Memberekaup13-Mar-11 13:22 
QuestionHow limitate the attribute of the root to it? Pin
Pierre besquent24-Feb-11 23:06
MemberPierre besquent24-Feb-11 23:06 
AnswerRe: How limitate the attribute of the root to it? Pin
dasblinkenlight9-Mar-11 3:20
Memberdasblinkenlight9-Mar-11 3:20 
QuestionIs Serialization worth it? Pin
Ger Hayden22-Feb-11 0:47
MemberGer Hayden22-Feb-11 0:47 
Questiongenerate xml based on schema. Pin
Ramkumar_S16-Feb-11 16:33
MemberRamkumar_S16-Feb-11 16:33 
AnswerRe: generate xml based on schema. Pin
Ger Hayden22-Feb-11 1:04
MemberGer Hayden22-Feb-11 1:04 
QuestionCustomizing RSS Feed - XSL to display rss your way. Pin
Sparx200914-Feb-11 3:36
MemberSparx200914-Feb-11 3:36 
AnswerRe: Customizing RSS Feed - XSL to display rss your way. Pin
Ravi Sant16-Feb-11 5:09
MemberRavi Sant16-Feb-11 5:09 
QuestionConverting some RTF text to WordML Pin
Ravi Sant8-Feb-11 20:55
MemberRavi Sant8-Feb-11 20:55 
QuestionHelp editing Xml file in C# Pin
jadughar3-Feb-11 22:32
Memberjadughar3-Feb-11 22:32 
AnswerRe: Help editing Xml file in C# Pin
Xmen Real 3-Feb-11 23:03
professional Xmen Real 3-Feb-11 23:03 
GeneralRe: Help editing Xml file in C# Pin
jadughar3-Feb-11 23:38
Memberjadughar3-Feb-11 23:38 
GeneralRe: Help editing Xml file in C# Pin
Xmen Real 3-Feb-11 23:41
professional Xmen Real 3-Feb-11 23:41 
GeneralRe: Help editing Xml file in C# Pin
jadughar3-Feb-11 23:57
Memberjadughar3-Feb-11 23:57 

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.