473,503 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

validating individual element names?

Hello,

Is there a way to validate an xml fragment? For example, I'd like to know
whether this tag is legal, and if not, what's wrong:

<complexType name="CIty Grid">

Thanks.
Nov 12 '05 #1
8 3925


Developer wrote:

Is there a way to validate an xml fragment? For example, I'd like to know
whether this tag is legal, and if not, what's wrong:

<complexType name="CIty Grid">


Even an XML fragment (not sure whether that is defined anywhere) needs
to have a matching closing tag for that start tag.

Also it is not clear what you have in mind, are you actually writing an
XML schema and want to check that? Or is that complexType just an
example of an XML element name?

If you want to create XML then you can use XmlTextWriter, it has a
method WriteName that takes a string argument and checks whether that is
an allowed XML name, if not it throws an exception.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #2
Read up this section of MSDN describing fragment validation using
XmlValidatingReader:
http://msdn.microsoft.com/library/de...tingReader.asp

"Developer" <wa******@mapinfo.nope.com> wrote in message
news:OG**************@tk2msftngp13.phx.gbl...
Hello,

Is there a way to validate an xml fragment? For example, I'd like to know
whether this tag is legal, and if not, what's wrong:

<complexType name="CIty Grid">

Thanks.

Nov 12 '05 #3
Thanks for the link. Is there an msxml equivalent, since I can't use the
..Net framework?

"Zafar Abbas [MSFT]" <za****@microsoft.com> wrote in message
news:OU*************@TK2MSFTNGP12.phx.gbl...
Read up this section of MSDN describing fragment validation using
XmlValidatingReader:
http://msdn.microsoft.com/library/de...tingReader.asp
"Developer" <wa******@mapinfo.nope.com> wrote in message
news:OG**************@tk2msftngp13.phx.gbl...
Hello,

Is there a way to validate an xml fragment? For example, I'd like to know whether this tag is legal, and if not, what's wrong:

<complexType name="CIty Grid">

Thanks.


Nov 12 '05 #4
I'm getting a well-formed schema from a server. Since it is well-formed, it
loads into an XmlDocument. I parse the element names, and need to detect
invalid ones.
I need to do this with msxml, if possible, since I can't use the .Net
framework.

Thanks for the reply.

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:uW**************@TK2MSFTNGP12.phx.gbl...


Developer wrote:

Is there a way to validate an xml fragment? For example, I'd like to know whether this tag is legal, and if not, what's wrong:

<complexType name="CIty Grid">


Even an XML fragment (not sure whether that is defined anywhere) needs
to have a matching closing tag for that start tag.

Also it is not clear what you have in mind, are you actually writing an
XML schema and want to check that? Or is that complexType just an
example of an XML element name?

If you want to create XML then you can use XmlTextWriter, it has a
method WriteName that takes a string argument and checks whether that is
an allowed XML name, if not it throws an exception.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #5


Developer wrote:
I'm getting a well-formed schema from a server. Since it is well-formed, it
loads into an XmlDocument. I parse the element names, and need to detect
invalid ones.
I need to do this with msxml, if possible, since I can't use the .Net
framework.


Yes, you can validate schemas by loading them into a schema cache, here
is an example:

var xmlSchemaCache = new ActiveXObject('Msxml2.XMLSchemaCache.4.0');
try {
xmlSchemaCache.add('', 'test20040809Xsd.xml');
}
catch (e) {
alert(e.message);
}

If the example schema test20040809Xsd.xml is as follows:

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

<xs:element name="element name" type="xs:string" />

</xs:schema>

then the error message is

PathToFile/javascript/test20040809Xsd.xml#/schema[1]/element[position()
= 1 and @name = 'element name']
Error parsing 'element name' as NCName datatype.
A name contained an invalid character.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #6
Thank you, Martin, I discovered that technique. Unfortunately, it is too
strict for what I need to do.
For example, it gives me an error on something like this:
<xsd:import namespace="http://www.opengis.net/gml"
schemaLocation="http://www.opengis.net/namespaces/gml/core/feature.xsd"/>
For my purposes, I don't care about that error, and once that problem is
detected, processing stops. An invalid name in a start tag, however, is
something I would like to know about.
So, I'm looking for a more granular approach: is this element name valid?
Is this start tag valid? This end tag?

Thanks again.
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:ux*************@TK2MSFTNGP09.phx.gbl...


Developer wrote:
I'm getting a well-formed schema from a server. Since it is well-formed, it loads into an XmlDocument. I parse the element names, and need to detect invalid ones.
I need to do this with msxml, if possible, since I can't use the .Net
framework.


Yes, you can validate schemas by loading them into a schema cache, here
is an example:

var xmlSchemaCache = new ActiveXObject('Msxml2.XMLSchemaCache.4.0');
try {
xmlSchemaCache.add('', 'test20040809Xsd.xml');
}
catch (e) {
alert(e.message);
}

If the example schema test20040809Xsd.xml is as follows:

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

<xs:element name="element name" type="xs:string" />

</xs:schema>

then the error message is

PathToFile/javascript/test20040809Xsd.xml#/schema[1]/element[position()
= 1 and @name = 'element name']
Error parsing 'element name' as NCName datatype.
A name contained an invalid character.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #7
MSXML does not let you selectively ignore validation errors. You will have
to use the .Net framework for that where you can hook up a validation event
handler and choose to proceed on the selective errors.

"Developer" <wa******@mapinfo.nope.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Thank you, Martin, I discovered that technique. Unfortunately, it is too
strict for what I need to do.
For example, it gives me an error on something like this:
<xsd:import namespace="http://www.opengis.net/gml"
schemaLocation="http://www.opengis.net/namespaces/gml/core/feature.xsd"/>
For my purposes, I don't care about that error, and once that problem is
detected, processing stops. An invalid name in a start tag, however, is
something I would like to know about.
So, I'm looking for a more granular approach: is this element name valid?
Is this start tag valid? This end tag?

Thanks again.
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:ux*************@TK2MSFTNGP09.phx.gbl...


Developer wrote:
I'm getting a well-formed schema from a server. Since it is well-formed, it loads into an XmlDocument. I parse the element names, and need to detect invalid ones.
I need to do this with msxml, if possible, since I can't use the .Net
framework.


Yes, you can validate schemas by loading them into a schema cache, here
is an example:

var xmlSchemaCache = new ActiveXObject('Msxml2.XMLSchemaCache.4.0');
try {
xmlSchemaCache.add('', 'test20040809Xsd.xml');
}
catch (e) {
alert(e.message);
}

If the example schema test20040809Xsd.xml is as follows:

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

<xs:element name="element name" type="xs:string" />

</xs:schema>

then the error message is

PathToFile/javascript/test20040809Xsd.xml#/schema[1]/element[position()
= 1 and @name = 'element name']
Error parsing 'element name' as NCName datatype.
A name contained an invalid character.
--

Martin Honnen
http://JavaScript.FAQTs.com/


Nov 12 '05 #8
Thanks, Zafar, that seems to answer my question -- I can't do it with msxml
4.

"Zafar Abbas [MSFT]" <za****@microsoft.com> wrote in message
news:OL*************@TK2MSFTNGP12.phx.gbl...
MSXML does not let you selectively ignore validation errors. You will have
to use the .Net framework for that where you can hook up a validation event handler and choose to proceed on the selective errors.

Nov 12 '05 #9

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

Similar topics

1
1670
by: Honza Pazdziora | last post by:
Hello, I'm processing documents that can have any element names in them. The only restriction is placed on the attributes of these elements, each of them can only have two attributes of given...
30
3855
by: Toni Mcintyre | last post by:
i'm having 2 problems with the http://validator.w3.org 1. if i have: <meta http-equiv="Content-Script-Type" content="text/javascript"> then why do i need <script type=text/javascript>...
6
6308
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334,...
1
2944
by: Andy | last post by:
I am having some trouble validating XML using the XmlValidatingReader. I have created some xml and used the visual studio to generate the schema. So I am confident that the xml and schema match. ...
0
1131
by: Adam Smith | last post by:
Hello. I have a document schema which imports the schema of four other documents. The problem is that when validating a document in the multiple import scenario, I get a timeout and then it...
1
4206
by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end...
0
1543
by: Joe | last post by:
Hi For a while now I have been finding postings of problems with the validating event not firing on controls properly. I too had this problem. The event would fire when clicking on another...
1
5262
by: cemcat | last post by:
Hello, We have an ASP.NET 2.0 (C#) web form that contains a textbox for users to enter multiple e-mail addresses separated by semicolons. We need to validate that each individual e-mail address...
7
1732
by: Bruce HS | last post by:
I'd like to call my ancestor Validation Function every time any control on a Win Form generates a Validating or Validated event. I'm using VB. I've extended Textbox, for instance, to have its...
0
7205
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,...
0
7093
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...
0
7287
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,...
0
7353
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...
1
7011
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...
0
5596
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,...
0
4689
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...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.