Results 1 to 4 of 4

Thread: XSD: How do schemas point out errors?

  1. #1

    Thread Starter
    Hyperactive Member singularis's Avatar
    Join Date
    Nov 2006
    Location
    Over There!
    Posts
    372

    Unhappy XSD: How do schemas point out errors?

    I have edited simple.xml slightly and added another element (called "bad") that should result in the document being invalid. Yet the schema does not pick up on this.

    I was using Internet Explorer 7 to read the xml file. Any help would be good

    Contents of Simple.xsd (the schema):
    Code:
    <?xml version = "1.0" encoding = "UTF-8"?>
    <!--Generated by XML Authority. Conforms to w3c http://www.w3.org/2001/XMLSchema-->
    <xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
    	<xsd:element name = "vehicles">
    		<xsd:complexType>
    			<xsd:sequence>
    				<xsd:element name = "nickname" type = "xsd:string" maxOccurs = "unbounded"/>
    			</xsd:sequence>
    		</xsd:complexType>
    	</xsd:element>
    </xsd:schema>
    Attached Files Attached Files
    Last edited by singularis; Jul 12th, 2007 at 10:09 AM.
    If what I said was helpful, give me rep!

    My Complete Games: -- 2D Zone (Space Shooter game) || _2D Zone 2_ || Ninja Blob (2D platformer) || Dren (Co-op up to 4 player base defence game)

    My Projects: -- The Dread Engine (2D VB game Engine) || A* Path Finding


    An excellent site for learning DirectX7, 8 & 9 (for VB6, C# & VB.net) would be: directx4vb.vbgamer.com --- For my projects and games see: pieper.freehostia.com

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: XSD: How do schemas point out errors?

    But it isn't valid. Check this out:
    http://tools.decisionsoft.com/schemaValidate/
    cvc-complex-type.2.4.a: Invalid content was found starting with element 'bad'. One of '{"":nickname}' is expected.

  3. #3

    Thread Starter
    Hyperactive Member singularis's Avatar
    Join Date
    Nov 2006
    Location
    Over There!
    Posts
    372

    Re: XSD: How do schemas point out errors?

    So you would need an XML validator....

    That answers a few questions
    If what I said was helpful, give me rep!

    My Complete Games: -- 2D Zone (Space Shooter game) || _2D Zone 2_ || Ninja Blob (2D platformer) || Dren (Co-op up to 4 player base defence game)

    My Projects: -- The Dread Engine (2D VB game Engine) || A* Path Finding


    An excellent site for learning DirectX7, 8 & 9 (for VB6, C# & VB.net) would be: directx4vb.vbgamer.com --- For my projects and games see: pieper.freehostia.com

  4. #4
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: XSD: How do schemas point out errors?

    I don't have the full version of VS so I'm not sure if there is some "automatically validate against schema" setting in the IDE when you create an XML file maybe?

    Anyway, so for validation, you can do something like this perhaps:
    vb.net Code:
    1. ' Check my Xml.
    2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.  
    4.         ' Setup the settings.
    5.         Dim rdrSets As New XmlReaderSettings()
    6.         With rdrSets
    7.             .ValidationType = ValidationType.Schema
    8.             .ValidationFlags = XmlSchemaValidationFlags.ProcessInlineSchema Or _
    9.                 XmlSchemaValidationFlags.ProcessSchemaLocation Or _
    10.                 XmlSchemaValidationFlags.ReportValidationWarnings
    11.         End With
    12.  
    13.         ' Validation event handler.
    14.         AddHandler rdrSets.ValidationEventHandler, AddressOf ValidateXML
    15.  
    16.         Dim rdr As XmlReader = XmlReader.Create("C:\simple.xml", rdrSets)
    17.  
    18.         ' Read the XML file.
    19.         Do While rdr.Read()
    20.         Loop
    21.  
    22.     End Sub
    23.  
    24.     Private Sub ValidateXML(ByVal sender As Object, ByVal e As ValidationEventArgs)
    25.         ' <bad> is not a good node.
    26.         MessageBox.Show("Error in validation: " & e.Message)
    27.     End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width