Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 9th, 2009, 07:54 AM
Authorized User
 
Join Date: Nov 2005
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to joxa83 Send a message via Yahoo to joxa83
Default Validate single node

how to validate sigle node against a schema?
 
Old January 9th, 2009, 08:02 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

You need to provide details of your context. Do you use the .NET framework and its DOM model for instance? Then there is a method Validate on the XmlDocument instance that you can use http://msdn.microsoft.com/en-us/library/ms162372.aspx
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old January 9th, 2009, 08:11 AM
Authorized User
 
Join Date: Nov 2005
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to joxa83 Send a message via Yahoo to joxa83
Default

I load a XMLDocument with some XML, then I select particular node, which I would like to validate.

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Schemas.Add(null, @"C:\Documents and Settings\ajoksimovic\My Documents\Visual Studio 2005\Projects\ConsoleApplication7\ConsoleApplicati on7\XMLSchema1.xsd");

xmlDoc.Load(@"C:\aco.xml");

xmlTemplateList = xmlDoc.DocumentElement.SelectNodes("//template");


Schema is

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1" targetNamespace="http://tempuri.org/XMLSchema1.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema1.xsd" xmlns:mstns="http://tempuri.org/XMLSchema1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="template">
<xs:complexType mixed="true">
<xs:sequence>
<xs:any minOccurs="0" />
</xs:sequence>
<xs:attribute name="datatableID" type="xs:unsignedInt" />
</xs:complexType>
</xs:element>

</xs:schema>


so each node in xmlTemplateList should validate against this schema, XMLDocument has overload for Validate

public void Validate(ValidationEventHandler validationEventHandler, XmlNode nodeToValidate); So i tried
xmlDoc.Validate(null,xmlTemplateList[0]) but it does not work in my case.

Last edited by joxa83; January 9th, 2009 at 08:20 AM..
 
Old January 9th, 2009, 08:21 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Well try the method I did post a link to in my first reply.
However note that in the sample that you posted your schema has a targetNamespace while the XPath you pass to SelectNodes selects elements named 'template' in no namespace. So the schema you have will never apply to the selected nodes.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
convert nodeset to a single node newbies1234 XSLT 2 August 18th, 2008 10:01 AM
Copying Source Node attributes to output node pvsat XSLT 2 November 3rd, 2005 09:46 AM
select single node bcadmin BOOK: XSLT Programmer's Reference, 2nd Edition 1 November 10th, 2004 12:15 PM
ASP.Net Single Single-on with Oracle Application S guhanath Oracle 0 October 6th, 2004 05:05 AM
How to validate a node in C++ ThunderBird XML 2 August 27th, 2004 11:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.