Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Validating XML against XSD

0 views
Skip to first unread message

Patrick Lam

unread,
Jun 25, 2002, 11:14:07 AM6/25/02
to
I know I could use System.Xml.XmlValidatingReader to validate XML against XSD.
 
However, it seems like in order to do that, my XML document need to have namespace defined (similar to those used in the XSD).  When I created my XML (and its child elements), I didn't actullay specify a namespace).  Could I get away with validating a XML that has neither the XSD namespace or the xsd path specified in the DocumentElement and for each child element under that?
 
I have created a function as follows to do the validation itself.
 

Private

Function ValidateAgainstXsd(ByVal objXmlDoc As XmlDocument, _

ByVal strXsdPath As String)

    Dim objDOMValidatingReader As XmlValidatingReader

    objDOMValidatingReader =
New XmlValidatingReader( _

    objXmlDoc.OuterXml, _

    XmlNodeType.Element, _

    Nothing
)

    objDOMValidatingReader.Schemas.Add(
Nothing, strXsdPath)

    objDOMValidatingReader.ValidationType = ValidationType.Schema

    AddHandler
objDOMValidatingReader.ValidationEventHandler, AddressOf ValidationHandler

    'While there is XML Elements - loop

    While
objDOMValidatingReader.Read()

    End
While

End Function

Dare Obasanjo

unread,
Jun 25, 2002, 2:50:39 PM6/25/02
to

There is no mandatory reason to include the "http://www.w3.org/XMLSchema" or
the "http://www.w3.org/XMLSchema-instance" namespace in valid instance
documents.

--
This posting is provided "AS IS" with no warranties, and confers no rights.

"Patrick Lam" <Patri...@unsubscribe.null> wrote in message
news:10250180...@ernani.logica.co.uk...

0 new messages