You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by "Stone, Timothy M" <ts...@ida.org> on 2010/03/09 21:13:03 UTC

Help validating XML against an XSD?

Greetings,

I am a bit new to the exciting world of XML validation.

I have installed xerces 3.0.1 on my MSVC++ 6.0 machine.  It seems to be
working, I can run the sample apps.

I have a local .xsd file on my machine and wish to test several .xml files
to see if they adhere to the specs of the .xsd file.  I cannot see how to
make any of the sample apps do this.

Can someone tell me what I am missing.  Thanks :)

tim








---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


RE: Help validating XML against an XSD?

Posted by Scott Cantor <ca...@osu.edu>.
> Hm, I've given it some offort, but cannot seem to get it going.  I have a
> .xsd and a .xml file, and I just want to test if the XML is compliant with
> the XSD.
> 
> I tried experimenting with the "count nodes" sample app, but can't get it.
> Could you provide the command line commands I need?

There's nothing about the command line that's really relevant other than the
-v option to set validation to auto or always. There is no option to control
schemaLocation from the command line, so your XML file needs to have an
xsi:schemaLocation attribute in the root to map the namespace to the schema
file or URL.

e.g. xsi:schemaLocation="namespace schema.xsd"

-- Scott



---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


RE: Help validating XML against an XSD?

Posted by Scott Cantor <ca...@osu.edu>.
> Another simple way to achieve the same is setting the
> fgXercesSchemaExternalSchemaLocation and
> fgXercesSchemaExternalNoNameSpaceSchemaLocation parameters (or using
> setExternalSchemaLocation and setExternalNoNamespaceSchemaLocation
> methods if available).

If you're writing code, yes, in contrast to just trying to use the utilities
as written, because they don't expose options for those settings (not that
they couldn't).

But it's also important to note that naively using those options won't work
either, because (in what I've always considered a buggy "feature", though
it's probably to spec) those overrides only apply to the schema lookup
*within* the XML instance being validated, and NOT to any lookup of imported
schemas in the schemas you pull in. They only go one layer deep, in other
words.

So a complete solution (in code) really has to register an EntityResolver
and fully hijack the whole mechanism in some brittle ways, unfortunately.

-- Scott



---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: Help validating XML against an XSD?

Posted by Vitaly Prapirny <ma...@mebius.net>.
Boris Kolpackov wrote:
> Hi Timothy,
>
> Stone, Timothy M<ts...@ida.org>  writes:
>
>> Hm, I've given it some offort, but cannot seem to get it going.  I have a
>> .xsd and a .xml file, and I just want to test if the XML is compliant with
>> the XSD.
>
> Seeing that this is becoming sort of a FAQ (though without a good answer),
> I have written a little post plus included a couple of examples that you
> may find useful:
>
> http://www.codesynthesis.com/~boris/blog/2010/03/15/validating-external-schemas-xerces-cxx/
>
> Boris
>

Another simple way to achieve the same is setting the 
fgXercesSchemaExternalSchemaLocation and 
fgXercesSchemaExternalNoNameSpaceSchemaLocation parameters (or using 
setExternalSchemaLocation and setExternalNoNamespaceSchemaLocation 
methods if available).

Good luck!
	Vitaly

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


RE: Help validating XML against an XSD?

Posted by Scott Cantor <ca...@osu.edu>.
> Seeing that this is becoming sort of a FAQ (though without a good answer),
> I have written a little post plus included a couple of examples that you
> may find useful:
> 
> http://www.codesynthesis.com/~boris/blog/2010/03/15/validating-external-
> schemas-xerces-cxx/

I think I know the answer, but is the fgXercesLoadSchema feature new in 3.x?

I seem to recall finding no reliable way to prevent it from following
imports in dependent schemas in the past without registering my own resolver
and playing some games, so my strategy has been to register the namespace ->
entity mappings in various ways, rather than registering and loading schemas
directly like your sample does. I suspect that still has to be done if
compatibility with 2.x is required.

-- Scott



---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: Help validating XML against an XSD?

Posted by "Stone, Timothy M" <ts...@ida.org>.
Hi Boris,

I really appreciate your help.  I am now back on this effort :)

Well, I have built xerces 3.0.1 on XP (3.0.1 because I use MSVC++ 6).

I have the supplied existing DOMPrint project that compiles and runs as a test that I really built xerces 3.0.1.

I thought just to get going I would add this new file (load-grammar-dom.cpp) to this project (since I know the project settings are correct).  I should probably rename main to something else so I don't have 2 :)

Unfortunately when I do this, the file will not compile.

Here are the first few errors:

--------------------Configuration: DOMCount - Win32 Release--------------------
Compiling...
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
cl /G6 /MD /W3 /GX /O2 /Ob2 /I "..\..\..\..\..\src" /D "NDEBUG" /D "_CONSOLE" /D "WIN32" /D "_WINDOWS" /FR"..\..\..\..\..\Build\Win32\VC6\Release\obj/" /Fo"..\..\..\..\..\Build\Win32\VC6\Release\obj/" /Fd"..\..\..\..\..\Build\Win32\VC6\Release\obj/" /FD /c
   "C:\Documents and Settings\Admin\Desktop\xerces-c-3.0.1\samples\src\DOMCount\load-grammar-dom.cpp"

load-grammar-dom.cpp
C:\Documents and Settings\Admin\Desktop\xerces-c-3.0.1\samples\src\DOMCount\load-grammar-dom.cpp(50) : error C2321: syntax error : unexpected 'DOMImplementationRegistry::getDOMImplementation'
C:\Documents and Settings\Admin\Desktop\xerces-c-3.0.1\samples\src\DOMCount\load-grammar-dom.cpp(53) : error C2061: syntax error : identifier 'impl'
C:\Documents and Settings\Admin\Desktop\xerces-c-3.0.1\samples\src\DOMCount\load-grammar-dom.cpp(59) : error C2061: syntax error : identifier 'parser'
(etc etc)

I know it must be something simple, but I'm a beginner.  Can someone tell me what I've done wrong?

thanks
tim



On 3/15/10 10:14 AM, "Boris Kolpackov" <bo...@codesynthesis.com> wrote:

> Hi Timothy,
>
> Stone, Timothy M <ts...@ida.org> writes:
>
>> Hm, I've given it some offort, but cannot seem to get it going.  I have a
>> .xsd and a .xml file, and I just want to test if the XML is compliant with
>> the XSD.
>
> Seeing that this is becoming sort of a FAQ (though without a good answer),
> I have written a little post plus included a couple of examples that you
> may find useful:
>
> http://www.codesynthesis.com/~boris/blog/2010/03/15/validating-external-schema
> s-xerces-cxx/
>
> Boris
>
> --
> Boris Kolpackov, Code Synthesis        http://codesynthesis.com/~boris/blog
> Open-source XML data binding for C++   http://codesynthesis.com/products/xsd
> XML data binding for embedded systems  http://codesynthesis.com/products/xsde
> Command line interface to C++ compiler http://codesynthesis.com/projects/cli
>

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Tim Stone                                    _/
Research Programmer/Analyst                 _/
Institute for Defense Analyses             _/
4850 Mark Center Dr.                      _/
Alexandria, VA 22311                     _/
(703) 845-6822                          _/
    "There's no place like 127.0.0.1"  _/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/



Re: Help validating XML against an XSD?

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi Timothy,

Stone, Timothy M <ts...@ida.org> writes:

> Hm, I've given it some offort, but cannot seem to get it going.  I have a
> .xsd and a .xml file, and I just want to test if the XML is compliant with
> the XSD.

Seeing that this is becoming sort of a FAQ (though without a good answer),
I have written a little post plus included a couple of examples that you
may find useful:

http://www.codesynthesis.com/~boris/blog/2010/03/15/validating-external-schemas-xerces-cxx/

Boris

-- 
Boris Kolpackov, Code Synthesis        http://codesynthesis.com/~boris/blog
Open-source XML data binding for C++   http://codesynthesis.com/products/xsd
XML data binding for embedded systems  http://codesynthesis.com/products/xsde
Command line interface to C++ compiler http://codesynthesis.com/projects/cli

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: Help validating XML against an XSD?

Posted by "Stone, Timothy M" <ts...@ida.org>.


On 3/9/10 5:01 PM, "Scott Cantor" <ca...@osu.edu> wrote:

>> I tried to turn on the functionality in the sample apps to control
>> validation as you mentioned but could not find an argument to specify my
>> .xsd file?  Only whether or not to do schema validation.  How do I plug my
>> file into the validator, and where would I look for the errors?
> 
> Badly, and on the console.
> 
> Locating schemas is a mess, but in general when validating files with
> precompiled tools you have to use xsi:schemaLocation hints either in the
> document or as a command line option (when supported, I don't recall if the
> sample apps support that).


Hm, I've given it some offort, but cannot seem to get it going.  I have a
.xsd and a .xml file, and I just want to test if the XML is compliant with
the XSD.

I tried experimenting with the "count nodes" sample app, but can't get it.
Could you provide the command line commands I need?


> 
> Real applications need to prevent schema hijacking and generally have to
> provide schema mapping functionality inside themselves. XML Catalogs are
> also a standard for this, and not one Xerces-C supports.
> 
>> I am trying to write an XML validator that I can hand out to other people,
>> so I cannot write the code to do it in the actual app that creates the
> XML.
> 
> I didn't mean that, I just meant if you weren't writing your own code, you'd
> have more luck with tools designed for validation.


I'm starting to wonder if I can use a standalone validator and just call it
from my app.  The problem is I need to be able to do that from Mac, Linux,
and Windows.  That is why I am trying to use xerces.  Any other paths you
might suggest?

thanks
tim






---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


RE: Help validating XML against an XSD?

Posted by Scott Cantor <ca...@osu.edu>.
> I tried to turn on the functionality in the sample apps to control
> validation as you mentioned but could not find an argument to specify my
> .xsd file?  Only whether or not to do schema validation.  How do I plug my
> file into the validator, and where would I look for the errors?

Badly, and on the console.

Locating schemas is a mess, but in general when validating files with
precompiled tools you have to use xsi:schemaLocation hints either in the
document or as a command line option (when supported, I don't recall if the
sample apps support that).

Real applications need to prevent schema hijacking and generally have to
provide schema mapping functionality inside themselves. XML Catalogs are
also a standard for this, and not one Xerces-C supports.

> I am trying to write an XML validator that I can hand out to other people,
> so I cannot write the code to do it in the actual app that creates the
XML.

I didn't mean that, I just meant if you weren't writing your own code, you'd
have more luck with tools designed for validation.

-- Scott



---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: Help validating XML against an XSD?

Posted by "Stone, Timothy M" <ts...@ida.org>.


On 3/9/10 4:06 PM, "Scott Cantor" <ca...@osu.edu> wrote:

>> I have a local .xsd file on my machine and wish to test several .xml files
>> to see if they adhere to the specs of the .xsd file.  I cannot see how to
>> make any of the sample apps do this.
> 
> They aren't really geared for that, but most of them have an option to
> control validation options in the course of doing whatever they explicitly
> set out to do (e.g. count nodes).
> 
> Using a library to do validation isn't really a good use of your time if
> your goal is to actually validate XML files, vs. writing code to do that
> inside your own applications.
> 
> -- Scott
> 

Hi

Thanks for the input.

I tried to turn on the functionality in the sample apps to control
validation as you mentioned but could not find an argument to specify my
.xsd file?  Only whether or not to do schema validation.  How do I plug my
file into the validator, and where would I look for the errors?

I am trying to write an XML validator that I can hand out to other people,
so I cannot write the code to do it in the actual app that creates the XML.

thanks
tim



---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


RE: Help validating XML against an XSD?

Posted by Scott Cantor <ca...@osu.edu>.
> I have a local .xsd file on my machine and wish to test several .xml files
> to see if they adhere to the specs of the .xsd file.  I cannot see how to
> make any of the sample apps do this.

They aren't really geared for that, but most of them have an option to
control validation options in the course of doing whatever they explicitly
set out to do (e.g. count nodes).

Using a library to do validation isn't really a good use of your time if
your goal is to actually validate XML files, vs. writing code to do that
inside your own applications.

-- Scott



---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org