473,770 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validate fragment

Hi NG,

I would need to validate an XML fragment against a type defined within
an XSD (which defines many other things). What is the correct way of
achieving this?
QD2004
Jul 20 '05 #1
1 1754


QuantDev wrote:
I would need to validate an XML fragment against a type defined within
an XSD (which defines many other things). What is the correct way of
achieving this?


That depends on the validating XML parser you are using, for instance
MSXML 5, Microsoft COM based XML parser version 5, currently only
available with other MS software like Office 2003, has a method named
validateNode
for its XML DOM document that allows you to validate the node (including
any descendants) against the currently loaded schemas.
Unfortunatly that functionality is not available in MSXML 4, the version
you can download from http://msdn.microsoft.com/.
The documentation for the method of MSXML 5 is here:
<http://msdn.microsoft. com/library/default.asp?url =/library/en-us/xmlsdk/html/xmmth_validateN ode.asp>

If you have a simple schema constraining the contents of <god> elements
to NCNames:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">

<xs:element name="gods">
<xs:complexType >
<xs:sequence>
<xs:element name="god" type="xs:NCName " maxOccurs="unbo unded" />
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

and an instance like

<?xml version="1.0" encoding="UTF-8"?>
<gods
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "test2005040701 Xsd.xml">

<god>Kibo</god>

</gods>

then the following client-side JScript example adds an new element with
content requested from the user and then validates the newly introduced
node:

var xmlDocument = new ActiveXObject(' Msxml2.DOMDocum ent.5.0');
xmlDocument.asy nc = false;
var valid = xmlDocument.loa d('test20050407 01.xml');

if (valid) {
var newGod = xmlDocument.cre ateElement('god ');
var newName = prompt('Who is your GOD?', '');
newGod.appendCh ild(xmlDocument .createTextNode (newName));
xmlDocument.doc umentElement.ap pendChild(newGo d);
var parseError = xmlDocument.val idateNode(newGo d);
if (parseError.err orCode != 0) {
alert(parseErro r.reason);
}
else {
alert(xmlDocume nt.xml);
}
}

The new validation API in Java 1.5 also allows you to validate a DOM
node against a loaded schema.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2

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

Similar topics

4
1815
by: Stuart Baker | last post by:
I just added session support to a web site and the URL's that contain a #fragment no longer function. Is there a delimiter that I can add following the #fragment that will tell the browser that the SID information is not part of the #fragment? Thanks in advance. Stuart Baker
22
4762
by: Haines Brown | last post by:
I have a document with a set of internal links such as: <a name="Z1"></a>... <a name="Z2"></a>... The W3C validator objects to the first instance of the name attribute: There is no attribute "FOO" for this element (in this HTML version). The element is defined not to have this attribute. These anchors are not contained in anything. For example, the Z1
0
1346
by: MG | last post by:
The following below is Microsoft sample to validate a XML document. My question is how can I put the validate errors in DataGrid? Using the ValidationEventHandle subroutine and adding ListBox control in that event works find but i can't firgure out to use a DataGrid instead. Can someone help, Please.? Dim m_success As Boolean Public Sub ValidationEventHandle(ByVal sender As Object, ByVal args As ValidationEventArgs)
2
4170
by: Yuriy | last post by:
Hi, any ideas how to read XML fragment from TextReader? XmlTextReader constructor accepts only Stream or string as source Do I miss something? thanks Yuriy
24
7131
by: Arno R | last post by:
Hi all, I have a client with several shoe-shops. Customers can leave their email-address if they want to be notified when there is a sale. Input is validated with instr() I am checking for @ and . (required) and also checking for spaces (not allowed). But: A LOT (5-10%) of the addresses still are wrong; (provider doesn't exist) or email-address not valid (anymore). When sending bulk-mail its a nasty problem to get the false addresses...
3
1465
by: CK | last post by:
I am doing a Doc.Loadxml(myxml) and I have an xsd schema that I want to validate the myxml against. How can I do this. code would help. Thanks in advance.
3
2078
by: Gustaf | last post by:
I'm trying to grasp this little passage from the XBRL spec: "The xlink:href attribute MUST be a URI. The URI MUST point to an XML document or to one or more XML fragments within an XML document. If the URI is relative, it MUST be resolved to obtain an absolute URI as specified in XML Base specification ." I guess they really mean "URI reference" and not "URI" in the formal sense. But anyway, consider this document:
2
2010
by: Miguel Isidoro | last post by:
Hi all, I am trying to include a xsd:unique element in my schema to make an attribute of an element unique at the whole document level. Consider the following xml fragment: <Form> <Question> <Response id="response1">
1
3345
by: Andy Dingley | last post by:
On 31 Jul 2008 16:22:51 GMT, "mark4asp" <mark4asp@gmail.comwrote: It's hard to programatically validate HTML. You need to use Jade, because Mere Mortals don't get to go near the code that does it otherwise. Even that's not easy. An easier way is to make valid code, then check it, just the once, by loading it into a browser that supports validation, such as Firefox with Marc Gueury's plugin. Provided that you code is actualy valid...
0
9453
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10254
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...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9904
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
8929
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
7451
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
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
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.