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="SomeProcN ame">
<Param name="@SomePara m" dataType="Char" dataLength="3"
direction="Inpu t">MHR</Param>
</Proc>
<Email>
<Success addresses="Some Email" subject="Some Subject"
body="Some Body." />
<Failure addresses="Anot herEmail;AndAno ther" subject="Some
Subject." body="SomeBody" />
</Email>
</XmlCommand>
And here is my Schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XmlCommand " elementFormDefa ult="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="XmlComman d">
<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="dataLengt h" use="optional"
type="xs:string " />
<xs:attribute name="direction " use="optional"
type="xs:string " />
<xs:attribute name="precision " use="optional"
type="xs:positi veInteger" />
<xs:attribute name="scale" use="optional"
type="xs:positi veInteger" />
</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="connectio nKey" use="required"
type="xs:string " />
<xs:attribute name="commandTi meout" use ="optional"
type="xs:positi veInteger" />
<xs:attribute name="appId" use="optional"
type="xs:positi veInteger" />
<xs:attribute name="appScreen Type" use="optional"
type="xs:positi veInteger" />
</xs:complexType>
</xs:element>
</xs:schema>
and here is my code:
Private Function LoadXml(ByVal xmlCommandStrin g As String) As
XmlDocument
Dim settings As XmlReaderSettin gs = New
XmlReaderSettin gs()
settings.Schema s.Add(Nothing,
Server.MapPath( schemaFileName) )
settings.Valida tionType = ValidationType. Schema
settings.Valida tionFlags = settings.Valida tionFlags And
XmlSchemaValida tionFlags.Repor tValidationWarn ings
AddHandler settings.Valida tionEventHandle r, New
ValidationEvent Handler(Address Of ValidationEvent Handler)
Dim stringRdr As New StringReader(xm lCommandString)
Dim xmlRdr As XmlReader
xmlRdr = XmlReader.Creat e(stringRdr, settings)
Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.Load(xml Rdr)
Return xmlDoc
End Function
Private Shared Sub ValidationEvent Handler(ByVal sender As Object,
ByVal args As ValidationEvent Args)
Throw New XmlSchemaExcept ion(schemaFileV alidationErrorM essage
& 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 " />