473,379 Members | 1,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Trying to validate just a subset of an Xml Document

Folks,

I'm faced with a dilemma here - I have an XML document and for part of it, I
have an XSD schema to validate it - but not for the rest of it.

Can I still validate at least part of the XML document?

I was hoping to use the XmlDocument.Validate(ValidationEventHandler,
XmlNode) method for that - doesn't seem to work...

My XML looks roughly like this (massively simplified):

<root>
<header>
....
</header>
<new>
<contract>
<Product value="4420" />
<ValidityDate value="2007-03-01" />
<UserId value="garaio" />
<ExternalReference value="9901" />
....
<details>
.....
......
....
</details>
</contract>
</new>
</root>

I basically have an XSD for the <contract>....</contractpart, so I was
hoping to do something like this:

XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas.Add(null, fullName);
settings.ValidationType = ValidationType.Schema;

XmlDocument doc = new XmlDocument();
doc.Load(<xml file name>);

XmlSchema contractSchema = XmlSchema.Read(new StreamReader(<xsd file
name>), new ValidationEventHandler(<schema validation handler>));

doc.Schemas.Add(contractSchema);

XmlNode contractNode = doc.SelectSingleNode('//contract');

if (contractNode != null)
{
doc.Validate(<doc validation handler>, contractNode);
}
The error message I get is:

"Schema information could not be found for the node passed into Validate.
The node may be invalid in its current position. Navigate to the ancestor
that has schema information, then call Validate again."

and I can't quite make out what it's trying to tell me.....

Any ideas??
I can easily validate a sub-document (if I modify the XML to include ONLY
the parts that I can validate) with a validating XML text reader..... so I
guess the XSD should be okay, really. It's just a matter of applying it when
the XML is loaded into an XmlDocument and I want to validate only a subset
of that document.
Any hints would be most welcome !

Marc

Mar 13 '07 #1
0 2620

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

Similar topics

1
by: user | last post by:
Hi, I am fairly new to XML, and would like some pointers on the following : I need to validate a _part_ of an xml file with a schema, and do not care what is there above/below that chunk. I...
1
by: Unknown User | last post by:
I just put an iframe in my page, but now the page doesn't validate. I guess I'm using legacy code: <iframe src="produtos.html" id="show-hide" frameborder="0" scrolling="no"></iframe> If I...
6
by: Abby Lee | last post by:
I must confirm the user enters a value for each fund they need. I do not know how many fund entries there will be...it's expandable to handle each users needs. I must varify each fund they enter is...
1
by: Ron Rohrssen | last post by:
I've been working on learning XML schemas and trying to make use of the MS classes for validating data against a schema. So, I've been trying to work through some simple schemas and instances....
0
by: SHC | last post by:
Hi all, I have a VC++ .NET 2003 - Windows XP Pro PC. I created a Win32 console application in my VC++ .NET 2003 and copied validateDOM.cpp, books.xml and books.xsd (see the attached files below)...
4
by: Mr. x | last post by:
Hello, I know about the validator on : http://validator.w3.org , which can validate html pages. I just new to this validator. How can I validate (if it can be - by this validator) aspx pages,...
12
by: Jim Anderson | last post by:
This is my first attempt at XML documentation. I'm trying to get started with docbook so I can put a set of documentation into docbook tags. I'm using 'XML In A Nutshell" and "DocBook The...
2
by: bbawa1 | last post by:
have to validate my web page using java script. I have one dropdown list also . I need a javascript to validate weather any item in dropdownlist is selected or not. e.g ddlDrop is my dropdownlist....
1
by: SkipNRun | last post by:
I am a novice when comes to JavaScript, AJAX. I am working on a form, which will allow users to update their contact information. In order to make the form flexible, I need to use pull down list. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.