Hi,
I am trying to use a validation method against this xml and keep
getting 'The 'name' attribute is not declared' and I can't figure out
why.
Here is my XML:
<XmlCommand xmlns="http://intranet/hstServices/Schemas/XmlCommand.xsd"
connectionKey="SomeKey" commandTimeout="60" appId="122"
appScreenType="879">
<Proc name="SomeProcName">
<Param name="@SomeParam" dataType="Char" dataLength="3"
direction="Input">MHR</Param>
</Proc>
<Email>
<Success addresses="SomeEmail" subject="Some Subject"
body="Some Body." />
<Failure addresses="AnotherEmail;AndAnother" subject="Some
Subject." body="SomeBody" />
</Email>
</XmlCommand>
And here is my Schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XmlCommand" elementFormDefault="qualified"
version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://intranet/hstServices/Schemas/XmlCommand.xsd"
xmlns="http://intranet/hstServices/Schemas/XmlCommand.xsd"
xmlns:NS="http://intranet/hstServices/Schemas/XmlCommand.xsd">
<xs:attribute name="name" type="xs:string" />
<xs:element name="XmlCommand">
<xs:complexType>
<xs:sequence>
<xs:element name="Proc" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="Param" nillable="true">
<xs:complexType>
<xs:sequence>
<xs:any processContents="skip" />
</xs:sequence>
<xs:attribute ref="name" use="required" />
<xs:attribute name="dataType" use="optional"
type="xs:string" />
<xs:attribute name="dataLength" use="optional"
type="xs:string" />
<xs:attribute name="direction" use="optional"
type="xs:string" />
<xs:attribute name="precision" use="optional"
type="xs:positiveInteger" />
<xs:attribute name="scale" use="optional"
type="xs:positiveInteger" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute ref="name" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="Email" nillable="true">
<xs:complexType>
<xs:sequence>
<xs:element name="Success">
<xs:complexType>
<xs:sequence>
</xs:sequence>
<xs:attribute name="addresses" use="optional"
type="xs:string" />
<xs:attribute name="subject" use="optional"
type="xs:string" />
<xs:attribute name="body" use="optional"
type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="Failure">
<xs:complexType>
<xs:sequence>
</xs:sequence>
<xs:attribute name="addresses" use="optional"
type="xs:string" />
<xs:attribute name="subject" use="optional"
type="xs:string" />
<xs:attribute name="body" use="optional"
type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="connectionKey" use="required"
type="xs:string" />
<xs:attribute name="commandTimeout" use ="optional"
type="xs:positiveInteger" />
<xs:attribute name="appId" use="optional"
type="xs:positiveInteger" />
<xs:attribute name="appScreenType" use="optional"
type="xs:positiveInteger" />
</xs:complexType>
</xs:element>
</xs:schema>
and here is my code:
Private Function LoadXml(ByVal xmlCommandString As String) As
XmlDocument
Dim settings As XmlReaderSettings = New
XmlReaderSettings()
settings.Schemas.Add(Nothing,
Server.MapPath(schemaFileName))
settings.ValidationType = ValidationType.Schema
settings.ValidationFlags = settings.ValidationFlags And
XmlSchemaValidationFlags.ReportValidationWarnings
AddHandler settings.ValidationEventHandler, New
ValidationEventHandler(AddressOf ValidationEventHandler)
Dim stringRdr As New StringReader(xmlCommandString)
Dim xmlRdr As XmlReader
xmlRdr = XmlReader.Create(stringRdr, settings)
Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.Load(xmlRdr)
Return xmlDoc
End Function
Private Shared Sub ValidationEventHandler(ByVal sender As Object,
ByVal args As ValidationEventArgs)
Throw New XmlSchemaException(schemaFileValidationErrorMessag e
& args.Message)
End Sub
I think the problem is related to the first instance of this attribute
(above the XMLCommand node) but I don't know where/how to set this
value. It also won't let me remove it without causing issues when I
try to load the xml in the XMLDoc object. Does anyone have any ideas
what is causing this?
<xs:attribute name="name" type="xs:string" />