473,765 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validation errors in xml file

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 " />

Apr 20 '07
14 8017
Doug wrote:
Here is my schema:
[snip]
and my XML hasn't changed:
[snip]

That XML validates just fine against the schema with Visual Studio 2005.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 23 '07 #11
That XML validates just fine against the schema with Visual Studio 2005.

I don't get it then. I am using the same xml, the same schema and
the .NET code that I produced earlier and I am getting the error I
described. At this point, I'm ready to scrap the validation method
altogether because it is more trouble than it's worth.

Apr 23 '07 #12
I found out why it won't validate but not what to do about it. The
problem is (and I apologize for not showing you this in my example) is
that I need multiple Param rows as such. The moment I do that, I get
that error I mentioned previously (if I have only one row, it
validates fine). How do I update the schema so I can have multiple
rows?
<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>
<Param name="@SomeOthe rParam" dataType="Char" dataLength="3"
direction="Inpu t">ABC</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>

Apr 23 '07 #13
Doug wrote:
I found out why it won't validate but not what to do about it. The
problem is (and I apologize for not showing you this in my example) is
that I need multiple Param rows as such. The moment I do that, I get
that error I mentioned previously (if I have only one row, it
validates fine). How do I update the schema so I can have multiple
rows?
Change
<xs:element name="Proc" minOccurs="1">
<xs:complexType >
<xs:sequence>
<xs:element name="Param" nillable="true" >

to

<xs:element name="Proc" minOccurs="1">
<xs:complexType >
<xs:sequence>
<xs:element name="Param" nillable="true"
maxOccurs="unbo unded">

(or if you want to allow e.g. a maximum of ten such Param elements then
obviously e.g.

<xs:element name="Proc" minOccurs="1">
<xs:complexType >
<xs:sequence>
<xs:element name="Param" nillable="true" maxOccurs="10">
)
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 23 '07 #14
That did it! Thank you!
Apr 23 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1713
by: motoman | last post by:
i have the following code (see below), i run my validation and get unexpected results. Public ID: null System ID: file:///C:/DATA/Sandpit/Eclipse/workspace/dtdValidation/memory.xml Line number: 4 Column number: 44 Message: Element type "memories" must be declared. Public ID: null
2
5188
by: Sudip Chakraborty | last post by:
Is there a way to see constraint validation errors while loading xml into a DataSet ? I'm interested in the line number in the xml file which is causing the error. I've enclosed the relevant stack trace below. at System.Data.DataSet.FailedEnableConstraints() at System.Data.DataSet.EnableConstraints() at System.Data.DataSet.set_EnforceConstraints(Boolean value)
6
2283
by: Stephen | last post by:
Hi, Does Validation controls like "Required field validator".... ever work with Netscape or we have to write javascript for either client-side or write server side validation. Please advice. Stephen
1
6406
by: billa1972 | last post by:
Hi, I am trying to hook into Yellow Freight's rating webservice. Below is the wsdl. When i try and create a proxy file with wsdl.exe i get the following errors, see below. Also, when i reference this wsdl in .NET it seems to do it fine, yet there are no objects to reference except RateQuoteBeanService. In the WSDL it looks like there should be getRateQuote, and QUOTEREQUEST, etc.
12
2270
by: Nalaka | last post by:
Hi, I suddenly started getting a lot of errors from html validation (some CSS) so I followed the following instructions to disable it. If you'd rather not have these types of HTML validation errors show up in your error-list, you can disable this functionality by selecting the Tools->Options menu item in VS or Visual Web Developer. Select the TextEditor->Html->Validation tree option in the left-hand side of the
9
4180
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation (e.g. this is numeric, this is alpha-numeric, etc.)
7
6997
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form is correct I need to submit to another page that uses the form data. I first tried making the form submit action= field point to the same file. When the form was correct, I tried loading the next page by using <META http-equiv refresh>. But...
27
4753
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
6
2735
by: lists | last post by:
Hi all, I am trying to validate an XML file against an XSD schema file within a ..NET C++ program, but the validation doesn't seem to be occuring. My code is listed below. The validation event handler is not called even when the XML should valid properly against the schema. Obviously I'm missing something. Can anyone help?
3
4071
by: Adhal | last post by:
Hello, I have an XML and XSD file. When I do validation in the XML file I only get the first error. Is it possible to list all errors? One other question. -------------Microsoft Sample Code ------------------- XmlReaderSettings settings = new XmlReaderSettings(); settings.Schemas.Add("http://www.contoso.com/books", "contosoBooks.xsd");
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.