1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-25 10:50:08 +03:00

merged the current state of XML Schemas implementation, it is not

* Makefile.am TODO_SCHEMAS configure.in genUnicode.py testAutomata.c
 testRegexp.c testSchemas.c xmlregexp.c xmlschemas.c xmlschemastypes.c
 xmlunicode.c include/libxml/Makefile.am
 include/libxml/schemasInternals.h include/libxml/xmlautomata.h
 include/libxml/xmlregexp.h include/libxml/xmlschemas.h
 include/libxml/xmlschemastypes.h include/libxml/xmlunicode.h
 include/libxml/xmlversion.h.in : merged the current state of
 XML Schemas implementation, it is not configured in by default,
 a specific --schemas configure option has been added.
* test/automata test/regexp test/schemas Makefile.am
  result/automata result/regexp result/schemas:
  merged automata/regexp/schemas regression tests
Daniel
This commit is contained in:
Daniel Veillard 2002-04-16 15:50:10 +00:00
parent f7c730f074
commit 4255d50415
43 changed files with 15353 additions and 9 deletions

View File

@ -1,3 +1,18 @@
Tue Apr 16 17:46:43 CEST 2002 Daniel Veillard <daniel@veillard.com>
* Makefile.am TODO_SCHEMAS configure.in genUnicode.py testAutomata.c
testRegexp.c testSchemas.c xmlregexp.c xmlschemas.c xmlschemastypes.c
xmlunicode.c include/libxml/Makefile.am
include/libxml/schemasInternals.h include/libxml/xmlautomata.h
include/libxml/xmlregexp.h include/libxml/xmlschemas.h
include/libxml/xmlschemastypes.h include/libxml/xmlunicode.h
include/libxml/xmlversion.h.in : merged the current state of
XML Schemas implementation, it is not configured in by default,
a specific --schemas configure option has been added.
* test/automata test/regexp test/schemas Makefile.am
result/automata result/regexp result/schemas:
merged automata/regexp/schemas regression tests
Tue Apr 16 09:48:44 CEST 2002 Daniel Veillard <daniel@veillard.com>
* xpath.c: Gary found a compile time problem, fixes #78823

View File

@ -1,12 +1,12 @@
## Process this file with automake to produce Makefile.in
#AUTOMAKE_ OPTIONS=no-dependencies
# AUTOMAKE_ OPTIONS=no-dependencies
SUBDIRS = include . doc example python
INCLUDES = -I@srcdir@/include -I$(top_builddir)/include @THREAD_CFLAGS@ @Z_CFLAGS@
noinst_PROGRAMS=testSAX testHTML testXPath testURI testDocbook testThreads \
testC14N
testC14N testAutomata testSchemas testRegexp
bin_PROGRAMS = xmllint xmlcatalog
@ -22,15 +22,16 @@ libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \
parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c \
valid.c xlink.c HTMLparser.c HTMLtree.c debugXML.c xpath.c \
xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \
catalog.c globals.c threads.c c14n.c triostr.c trio.c
catalog.c globals.c threads.c c14n.c \
xmlregexp.c xmlschemas.c schemastypes.c xmlunicode.c \
triostr.c trio.c
else
libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \
parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c \
valid.c xlink.c HTMLparser.c HTMLtree.c debugXML.c xpath.c \
xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \
catalog.c globals.c threads.c c14n.c
catalog.c globals.c threads.c c14n.c \
xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.c
endif
DEPS = $(top_builddir)/libxml2.la
@ -86,11 +87,26 @@ testURI_LDFLAGS =
testURI_DEPENDENCIES = $(DEPS)
testURI_LDADD= $(LDADDS)
testRegexp_SOURCES=testRegexp.c
testRegexp_LDFLAGS =
testRegexp_DEPENDENCIES = $(DEPS)
testRegexp_LDADD= $(LDADDS)
testAutomata_SOURCES=testAutomata.c
testAutomata_LDFLAGS =
testAutomata_DEPENDENCIES = $(DEPS)
testAutomata_LDADD= $(LDADDS)
testSchemas_SOURCES=testSchemas.c
testSchemas_LDFLAGS =
testSchemas_DEPENDENCIES = $(DEPS)
testSchemas_LDADD= $(LDADDS)
check-local: tests
testall : tests SVGtests SAXtests
tests: XMLtests XMLenttests HTMLtests Validtests URItests XPathtests XPtrtests XIncludetests Scripttests Catatests @TEST_THREADS@
tests: XMLtests XMLenttests HTMLtests Validtests URItests XPathtests XPtrtests XIncludetests Scripttests Catatests @TEST_SCHEMAS@ @TEST_THREADS@
@(cd python ; $(MAKE) tests)
valgrind:
@ -557,6 +573,67 @@ Validtests : xmllint$(EXEEXT)
rm result.$$name error.$$name ; \
fi ; fi ; done)
Regexptests: testRegexp$(EXEEXT)
@(echo > .memdump)
@echo "##"
@echo "## Regexp regression tests"
@echo "##"
-@(for i in $(srcdir)/test/regexp/* ; do \
name=`basename $$i`; \
if [ ! -d $$i ] ; then \
if [ ! -f $(srcdir)/result/regexp/$$name ] ; then \
echo New test file $$name ; \
$(CHECKER) $(top_builddir)/testRegexp -i $$i > $(srcdir)/result/regexp/$$name; \
else \
echo Testing $$name ; \
$(CHECKER) $(top_builddir)/testRegexp -i $$i > result.$$name ; \
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
diff $(srcdir)/result/regexp/$$name result.$$name ; \
rm result.$$name ; \
fi ; fi ; done)
Automatatests: testAutomata$(EXEEXT)
@(echo > .memdump)
@echo "##"
@echo "## Automata regression tests"
@echo "##"
-@(for i in $(srcdir)/test/automata/* ; do \
name=`basename $$i`; \
if [ ! -d $$i ] ; then \
if [ ! -f $(srcdir)/result/automata/$$name ] ; then \
echo New test file $$name ; \
$(CHECKER) $(top_builddir)/testAutomata $$i > $(srcdir)/result/automata/$$name; \
else \
echo Testing $$name ; \
$(CHECKER) $(top_builddir)/testAutomata $$i > result.$$name ; \
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
diff $(srcdir)/result/automata/$$name result.$$name ; \
rm result.$$name ; \
fi ; fi ; done)
Schemastests: testSchemas$(EXEEXT)
@(echo > .memdump)
@echo "##"
@echo "## Schemas regression tests"
@echo "##"
-@(for i in $(srcdir)/test/schemas/*.xml ; do \
name=`basename $$i .xml`; \
if [ ! -f $(srcdir)/test/schemas/$$name.xsd ] ; then continue ; fi ; \
schemas="$(srcdir)/test/schemas/$$name.xsd" ; \
if [ ! -d $$i ] ; then \
if [ ! -f $(srcdir)/result/schemas/$$name ] ; then \
echo New test file $$name ; \
$(CHECKER) $(top_builddir)/testSchemas $$schemas $$i > $(srcdir)/result/schemas/$$name; \
else \
echo Testing $$name ; \
$(CHECKER) $(top_builddir)/testSchemas $$schemas $$i > result.$$name ; \
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
diff $(srcdir)/result/schemas/$$name result.$$name ; \
rm result.$$name ; \
fi ; fi ; done)
dist-hook: libxml.spec
-cp libxml.spec $(distdir)
(cd $(srcdir) ; tar -cf - --exclude CVS win32 macos vms test result SAXresult ) | (cd $(distdir); tar xf -)
@ -582,7 +659,7 @@ EXTRA_DIST = xml2-config.in xml2Conf.sh.in libxml.spec.in libxml.spec \
$(man_MANS) libxml-2.0.pc.in \
trionan.c trionan.h triostr.c triostr.h trio.c trio.h \
triop.h triodef.h libxml.h \
testThreadsWin32.c
testThreadsWin32.c genUnicode.py
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libxml-2.0.pc

31
TODO_SCHEMAS Normal file
View File

@ -0,0 +1,31 @@
- implement counted transitions at the automata level
- Unicode:
+ upgrade to 3.2
+ improve the python script to generate better test
expressions to check the list of ranges.
- Implement the interface at the SAX level
- Implement the missing parts in the Structure part
+ all content model
+ enumerations
+ countless others c.f. the TODO scattered in the code
- Complete the Built-In datatype collections and Facets implementations
- Regression tests based on
+ the primer:
http://www.w3.org/TR/xmlschema-0/
+ the Schemas Test Collection:
http://www.w3.org/2001/05/xmlschema-test-collection/
+ archives of the schemas-dev list
- Integrity constraints:
+ what's that ? How need to read about it
- "formal" checking, i.e. go through the full Structure spec and
bind code and associated parts of the Schemas spec
- go though the erratas
http://www.w3.org/2001/05/xmlschema-errata

View File

@ -274,6 +274,9 @@ if test "${LOGNAME}" = "veillard" -a "`pwd`" = "/u/veillard/XML" ; then
if test "${with_xptr}" = "" ; then
with_xptr="yes"
fi
if test "${with_schemas}" = "" ; then
with_schemas="yes"
fi
CFLAGS="-g -O -pedantic -W -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls "
dnl -Wcast-qual -ansi
fi
@ -513,6 +516,18 @@ M_LIBS="-lm"
XML_LIBS="-lxml2 $Z_LIBS $THREAD_LIBS $ICONV_LIBS $M_LIBS $LIBS"
AC_SUBST(WITH_ICONV)
AC_ARG_WITH(schemas, [ --with-schemas Add experimental Schemas support (off)])
if test "$with_schemas" = "yes" ; then
echo Enabling Schemas support
WITH_SCHEMAS=1
TEST_SCHEMAS="Regexptests Automatatests Schemastests"
else
WITH_SCHEMAS=0
TEST_SCHEMAS=
fi
AC_SUBST(WITH_SCHEMAS)
AC_SUBST(TEST_SCHEMAS)
AC_ARG_WITH(debug, [ --with-debug Add the debugging module (on)])
if test "$with_debug" = "no" ; then
echo Disabling DEBUG support

256
genUnicode.py Executable file
View File

@ -0,0 +1,256 @@
#!/usr/bin/python -u
import sys
import string
import time
sources = "Blocks-4.txt UnicodeData-3.1.0.txt"
try:
blocks = open("Blocks-4.txt", "r")
except:
print "Missing Blocks-4.txt, aborting ..."
sys.exit(1)
BlockNames = {}
for line in blocks.readlines():
if line[0] == '#':
continue
line = string.strip(line)
if line == '':
continue
try:
fields = string.split(line, ';')
range = string.strip(fields[0])
(start, end) = string.split(range, "..")
name = string.strip(fields[1])
name = string.replace(name, ' ', '')
except:
print "Failed to process line: %s" % (line)
continue
BlockNames[name] = ("0x"+start, "0x"+end)
blocks.close()
print "Parsed %d blocks descriptions" % (len(BlockNames.keys()))
try:
data = open("UnicodeData-3.1.0.txt", "r")
except:
print "Missing UnicodeData-3.1.0.txt, aborting ..."
sys.exit(1)
nbchar = 0;
Categories = {}
for line in data.readlines():
if line[0] == '#':
continue
line = string.strip(line)
if line == '':
continue
try:
fields = string.split(line, ';')
point = string.strip(fields[0])
value = 0
while point != '':
value = value * 16
if point[0] >= '0' and point[0] <= '9':
value = value + ord(point[0]) - ord('0')
elif point[0] >= 'A' and point[0] <= 'F':
value = value + 10 + ord(point[0]) - ord('A')
elif point[0] >= 'a' and point[0] <= 'f':
value = value + 10 + ord(point[0]) - ord('a')
point = point[1:]
name = fields[2]
except:
print "Failed to process line: %s" % (line)
continue
nbchar = nbchar + 1
try:
Categories[name].append(value)
except:
try:
Categories[name] = [value]
except:
print "Failed to process line: %s" % (line)
try:
Categories[name[0]].append(value)
except:
try:
Categories[name[0]] = [value]
except:
print "Failed to process line: %s" % (line)
blocks.close()
print "Parsed %d char generating %d categories" % (nbchar, len(Categories.keys()))
#reduce the number list into ranges
for cat in Categories.keys():
list = Categories[cat]
start = -1
prev = -1
end = -1
ranges = []
for val in list:
if start == -1:
start = val
prev = val
continue
elif val == prev + 1:
prev = val
continue
elif prev == start:
ranges.append((prev, prev))
start = val
prev = val
continue
else:
ranges.append((start, prev))
start = val
prev = val
continue
if prev == start:
ranges.append((prev, prev))
else:
ranges.append((start, prev))
Categories[cat] = ranges
#
# Generate the resulting files
#
try:
header = open("xmlunicode.h", "w")
except:
print "Failed to open xmlunicode.h"
sys.exit(1)
try:
output = open("xmlunicode.c", "w")
except:
print "Failed to open xmlunicode.c"
sys.exit(1)
date = time.asctime(time.localtime(time.time()))
header.write(
"""/*
* xmlunicode.h: this header exports interfaces for the Unicode character APIs
*
* This file is automatically generated from the
* UCS description files of the Unicode Character Database
* http://www.unicode.org/Public/3.1-Update/UnicodeCharacterDatabase-3.1.0.html
* using the genUnicode.py Python script.
*
* Generation date: %s
* Sources: %s
* Daniel Veillard <veillard@redhat.com>
*/
#ifndef __XML_UNICODE_H__
#define __XML_UNICODE_H__
#ifdef __cplusplus
extern "C" {
#endif
""" % (date, sources));
output.write(
"""/*
* xmlunicode.c: this module implements the Unicode character APIs
*
* This file is automatically generated from the
* UCS description files of the Unicode Character Database
* http://www.unicode.org/Public/3.1-Update/UnicodeCharacterDatabase-3.1.0.html
* using the genUnicode.py Python script.
*
* Generation date: %s
* Sources: %s
* Daniel Veillard <veillard@redhat.com>
*/
#define IN_LIBXML
#include "libxml.h"
#ifdef LIBXML_UNICODE_ENABLED
#include <string.h>
#include <libxml/xmlversion.h>
#include <libxml/xmlunicode.h>
""" % (date, sources));
keys = BlockNames.keys()
keys.sort()
for block in keys:
(start, end) = BlockNames[block]
name = string.replace(block, '-', '')
header.write("int\txmlUCSIs%s\t(int code);\n" % name)
output.write("/**\n * xmlUCSIs%s:\n * @code: UCS code point\n" % (name))
output.write(" *\n * Check whether the character is part of %s UCS Block\n"%
(block))
output.write(" *\n * Returns 1 if true 0 otherwise\n */\n");
output.write("int\nxmlUCSIs%s(int code) {\n" % name)
output.write(" return((code >= %s) && (code <= %s));\n" % (start, end))
output.write("}\n\n")
header.write("\nint\txmlUCSIsBlock\t(int code,\n\t\t\t const char *block);\n\n")
output.write("/**\n * xmlUCSIsBlock:\n * @code: UCS code point\n")
output.write(" * @block: UCS block name\n")
output.write(" *\n * Check whether the caracter is part of the UCS Block\n")
output.write(" *\n * Returns 1 if true, 0 if false and -1 on unknown block\n */\n");
output.write("int\nxmlUCSIsBlock(int code, const char *block) {\n")
keys = BlockNames.keys()
keys.sort()
for block in keys:
name = string.replace(block, '-', '')
output.write(" if (!strcmp(block, \"%s\"))\n return(xmlUCSIs%s(code));\n" %
(block, name));
output.write(" return(-1);\n}\n\n")
keys = Categories.keys()
keys.sort()
for name in keys:
ranges = Categories[name]
header.write("int\txmlUCSIsCat%s\t(int code);\n" % name)
output.write("/**\n * xmlUCSIsCat%s:\n * @code: UCS code point\n" % (name))
output.write(" *\n * Check whether the character is part of %s UCS Category\n"%
(name))
output.write(" *\n * Returns 1 if true 0 otherwise\n */\n");
output.write("int\nxmlUCSIsCat%s(int code) {\n" % name)
start = 1
for range in ranges:
(begin, end) = range;
if start:
output.write(" return(");
start = 0
else:
output.write(" ||\n ");
if (begin == end):
output.write("(code == %s)" % (hex(begin)))
else:
output.write("((code >= %s) && (code <= %s))" % (
hex(begin), hex(end)))
output.write(");\n}\n\n")
header.write("\nint\txmlUCSIsCat\t(int code,\n\t\t\t const char *cat);\n")
output.write("/**\n * xmlUCSIsCat:\n * @code: UCS code point\n")
output.write(" * @cat: UCS Category name\n")
output.write(" *\n * Check whether the caracter is part of the UCS Category\n")
output.write(" *\n * Returns 1 if true, 0 if false and -1 on unknown category\n */\n");
output.write("int\nxmlUCSIsCat(int code, const char *cat) {\n")
keys = Categories.keys()
keys.sort()
for name in keys:
output.write(" if (!strcmp(cat, \"%s\"))\n return(xmlUCSIsCat%s(code));\n" %
(name, name));
output.write(" return(-1);\n}\n\n")
header.write("""
#ifdef __cplusplus
}
#endif
#endif /* __XML_UNICODE_H__ */
""");
output.write("""
#endif /* LIBXML_UNICODE_ENABLED */
""");
header.close()
output.close()

View File

@ -32,7 +32,13 @@ xmlinc_HEADERS = \
catalog.h \
threads.h \
globals.h \
c14n.h
c14n.h \
xmlautomata.h \
xmlregexp.h \
xmlschemas.h \
schemasInternals.h \
xmlschemastypes.h \
xmlunicode.h
install-exec-hook:
$(mkinstalldirs) $(DESTDIR)$(xmlincdir)

View File

@ -0,0 +1,275 @@
/*
* schemasInternals.h : internal interfaces for the XML Schemas handling
* and schema validity checking
*
* See Copyright for the status of this software.
*
* Daniel.Veillard@w3.org
*/
#ifndef __XML_SCHEMA_INTERNALS_H__
#define __XML_SCHEMA_INTERNALS_H__
#if defined(WIN32) && defined(_MSC_VER)
#include <libxml/xmlwin32version.h>
#else
#include <libxml/xmlversion.h>
#endif
#ifdef LIBXML_SCHEMAS_ENABLED
#include <libxml/xmlregexp.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* XML Schemas defines multiple type of types.
*/
typedef enum {
XML_SCHEMA_TYPE_BASIC = 1,
XML_SCHEMA_TYPE_ANY,
XML_SCHEMA_TYPE_FACET,
XML_SCHEMA_TYPE_SIMPLE,
XML_SCHEMA_TYPE_COMPLEX,
XML_SCHEMA_TYPE_SEQUENCE,
XML_SCHEMA_TYPE_CHOICE,
XML_SCHEMA_TYPE_ALL,
XML_SCHEMA_TYPE_SIMPLE_CONTENT,
XML_SCHEMA_TYPE_COMPLEX_CONTENT,
XML_SCHEMA_TYPE_UR,
XML_SCHEMA_TYPE_RESTRICTION,
XML_SCHEMA_TYPE_EXTENSION,
XML_SCHEMA_TYPE_ELEMENT,
XML_SCHEMA_TYPE_ATTRIBUTE,
XML_SCHEMA_TYPE_GROUP,
XML_SCHEMA_TYPE_NOTATION,
XML_SCHEMA_TYPE_LIST,
XML_SCHEMA_TYPE_UNION,
XML_SCHEMA_FACET_MININCLUSIVE = 1000,
XML_SCHEMA_FACET_MINEXCLUSIVE,
XML_SCHEMA_FACET_MAXINCLUSIVE,
XML_SCHEMA_FACET_MAXEXCLUSIVE,
XML_SCHEMA_FACET_TOTALDIGITS,
XML_SCHEMA_FACET_FRACTIONDIGITS,
XML_SCHEMA_FACET_PATTERN,
XML_SCHEMA_FACET_ENUMERATION,
XML_SCHEMA_FACET_WHITESPACE,
XML_SCHEMA_FACET_LENGTH,
XML_SCHEMA_FACET_MAXLENGTH,
XML_SCHEMA_FACET_MINLENGTH
} xmlSchemaTypeType;
typedef enum {
XML_SCHEMA_CONTENT_UNKNOWN = 0,
XML_SCHEMA_CONTENT_EMPTY = 1,
XML_SCHEMA_CONTENT_ELEMENTS,
XML_SCHEMA_CONTENT_MIXED,
XML_SCHEMA_CONTENT_SIMPLE,
XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS,
XML_SCHEMA_CONTENT_BASIC
} xmlSchemaContentType;
typedef struct _xmlSchemaVal xmlSchemaVal;
typedef xmlSchemaVal *xmlSchemaValPtr;
typedef struct _xmlSchemaType xmlSchemaType;
typedef xmlSchemaType *xmlSchemaTypePtr;
typedef struct _xmlSchemaFacet xmlSchemaFacet;
typedef xmlSchemaFacet *xmlSchemaFacetPtr;
/**
* Annotation
*/
typedef struct _xmlSchemaAnnot xmlSchemaAnnot;
typedef xmlSchemaAnnot *xmlSchemaAnnotPtr;
struct _xmlSchemaAnnot {
struct _xmlSchemaAnnot *next;
xmlNodePtr content; /* the annotation */
};
/**
* An attribute definition.
*/
#define XML_SCHEMAS_ANYATTR_SKIP 1
#define XML_SCHEMAS_ANYATTR_LAX 2
#define XML_SCHEMAS_ANYATTR_STRICT 3
typedef struct _xmlSchemaAttribute xmlSchemaAttribute;
typedef xmlSchemaAttribute *xmlSchemaAttributePtr;
struct _xmlSchemaAttribute {
xmlSchemaTypeType type; /* The kind of type */
struct _xmlSchemaAttribute *next;/* the next attribute if in a group ... */
xmlChar *name;
xmlChar *id;
xmlChar *ref;
xmlChar *refNs;
xmlChar *typeName;
xmlChar *typeNs;
xmlSchemaAnnotPtr annot;
xmlSchemaTypePtr base;
int occurs;
xmlChar *defValue;
xmlSchemaTypePtr subtypes;
};
/**
* An attribute group definition.
*
* xmlSchemaAttribute and xmlSchemaAttributeGroup start of structures
* must be kept similar
*/
typedef struct _xmlSchemaAttributeGroup xmlSchemaAttributeGroup;
typedef xmlSchemaAttributeGroup *xmlSchemaAttributeGroupPtr;
struct _xmlSchemaAttributeGroup {
xmlSchemaTypeType type; /* The kind of type */
struct _xmlSchemaAttribute *next;/* the next attribute if in a group ... */
xmlChar *name;
xmlChar *id;
xmlChar *ref;
xmlChar *refNs;
xmlSchemaAnnotPtr annot;
xmlSchemaAttributePtr attributes;
};
/**
* Schemas type definition.
*/
#define XML_SCHEMAS_TYPE_MIXED 1 << 0
struct _xmlSchemaType {
xmlSchemaTypeType type; /* The kind of type */
struct _xmlSchemaType *next;/* the next type if in a sequence ... */
xmlChar *name;
xmlChar *id;
xmlChar *ref;
xmlChar *refNs;
xmlSchemaAnnotPtr annot;
xmlSchemaTypePtr subtypes;
xmlSchemaAttributePtr attributes;
xmlNodePtr node;
int minOccurs;
int maxOccurs;
int flags;
xmlSchemaContentType contentType;
xmlChar *base;
xmlChar *baseNs;
xmlSchemaTypePtr baseType;
xmlSchemaFacetPtr facets;
};
/**
* An element definition.
*
* xmlSchemaType, xmlSchemaFacet and xmlSchemaElement start of
* structures must be kept similar
*/
#define XML_SCHEMAS_ELEM_NILLABLE 1 << 0
#define XML_SCHEMAS_ELEM_GLOBAL 1 << 1
#define XML_SCHEMAS_ELEM_DEFAULT 1 << 2
#define XML_SCHEMAS_ELEM_FIXED 1 << 3
#define XML_SCHEMAS_ELEM_ABSTRACT 1 << 4
#define XML_SCHEMAS_ELEM_TOPLEVEL 1 << 5
#define XML_SCHEMAS_ELEM_REF 1 << 6
typedef struct _xmlSchemaElement xmlSchemaElement;
typedef xmlSchemaElement *xmlSchemaElementPtr;
struct _xmlSchemaElement {
xmlSchemaTypeType type; /* The kind of type */
struct _xmlSchemaType *next;/* the next type if in a sequence ... */
xmlChar *name;
xmlChar *id;
xmlChar *ref;
xmlChar *refNs;
xmlSchemaAnnotPtr annot;
xmlSchemaTypePtr subtypes;
xmlSchemaAttributePtr attributes;
xmlNodePtr node;
int minOccurs;
int maxOccurs;
int flags;
xmlChar *targetNamespace;
xmlChar *namedType;
xmlChar *namedTypeNs;
xmlChar *substGroup;
xmlChar *substGroupNs;
xmlChar *scope;
xmlChar *value;
struct _xmlSchemaElement *refDecl;
xmlRegexpPtr contModel;
};
/**
* An facet definition.
*
*/
#define XML_SCHEMAS_FACET_UNKNOWN 0
#define XML_SCHEMAS_FACET_PRESERVE 1
#define XML_SCHEMAS_FACET_REPLACE 2
#define XML_SCHEMAS_FACET_COLLAPSE 3
struct _xmlSchemaFacet {
xmlSchemaTypeType type; /* The kind of type */
struct _xmlSchemaFacet *next;/* the next type if in a sequence ... */
xmlChar *value;
xmlChar *id;
xmlSchemaAnnotPtr annot;
xmlNodePtr node;
int fixed;
int whitespace;
xmlSchemaValPtr val;
xmlRegexpPtr regexp;
};
/**
* A notation definition.
*/
typedef struct _xmlSchemaNotation xmlSchemaNotation;
typedef xmlSchemaNotation *xmlSchemaNotationPtr;
struct _xmlSchemaNotation {
xmlSchemaTypeType type; /* The kind of type */
xmlChar *name;
xmlSchemaAnnotPtr annot;
xmlChar *identifier;
};
/**
* A Schemas definition
*/
#define XML_SCHEMAS_QUALIF_ELEM 1 << 0
#define XML_SCHEMAS_QUALIF_ATTR 1 << 1
struct _xmlSchema {
xmlChar *name; /* schema name */
xmlChar *targetNamespace; /* the target namespace */
xmlChar *version;
xmlChar *id;
xmlDocPtr doc;
xmlSchemaAnnotPtr annot;
int flags;
xmlHashTablePtr typeDecl;
xmlHashTablePtr attrDecl;
xmlHashTablePtr attrgrpDecl;
xmlHashTablePtr elemDecl;
xmlHashTablePtr notaDecl;
};
void xmlSchemaFreeType (xmlSchemaTypePtr type);
#ifdef __cplusplus
}
#endif
#endif /* LIBXML_SCHEMAS_ENABLED */
#endif /* __XML_SCHEMA_INTERNALS_H__ */

View File

@ -0,0 +1,75 @@
/*
* automata.h : description of the API to build regexp automats
*
* See Copyright for the status of this software.
*
* Daniel Veillard <veillard@redhat.com>
*/
#ifndef __XML_AUTOMATA_H__
#define __XML_AUTOMATA_H__
#if defined(WIN32) && defined(_MSC_VER)
#include <libxml/xmlwin32version.h>
#else
#include <libxml/xmlversion.h>
#endif
#ifdef LIBXML_AUTOMATA_ENABLED
#include <libxml/xmlregexp.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* xmlAutomataPtr:
*
* A libxml automata description, It can be compiled into a regexp
*/
typedef struct _xmlAutomata xmlAutomata;
typedef xmlAutomata *xmlAutomataPtr;
/**
* xmlAutomataStatePtr:
*
* A state int the automata description,
*/
typedef struct _xmlAutomataState xmlAutomataState;
typedef xmlAutomataState *xmlAutomataStatePtr;
/*
* Building API
*/
xmlAutomataPtr xmlNewAutomata (void);
void xmlFreeAutomata (xmlAutomataPtr am);
xmlAutomataStatePtr xmlAutomataGetInitState (xmlAutomataPtr am);
int xmlAutomataSetFinalState(xmlAutomataPtr am,
xmlAutomataStatePtr state);
xmlAutomataStatePtr xmlAutomataNewState (xmlAutomataPtr am);
xmlAutomataStatePtr xmlAutomataNewTransition(xmlAutomataPtr am,
xmlAutomataStatePtr from,
xmlAutomataStatePtr to,
const xmlChar *token,
void *data);
xmlAutomataStatePtr xmlAutomataNewCountTrans(xmlAutomataPtr am,
xmlAutomataStatePtr from,
xmlAutomataStatePtr to,
const xmlChar *token,
int min,
int max,
void *data);
xmlAutomataStatePtr xmlAutomataNewEpsilon (xmlAutomataPtr am,
xmlAutomataStatePtr from,
xmlAutomataStatePtr to);
int xmlAutomataNewCounter (xmlAutomataPtr am);
xmlRegexpPtr xmlAutomataCompile (xmlAutomataPtr am);
#ifdef __cplusplus
}
#endif
#endif /* LIBXML_AUTOMATA_ENABLED */
#endif /* __XML_AUTOMATA_H__ */

View File

@ -0,0 +1,77 @@
/*
* regexp.h : describes the basic API for libxml regular expressions handling
*
* See Copyright for the status of this software.
*
* Daniel Veillard <veillard@redhat.com>
*/
#ifndef __XML_REGEXP_H__
#define __XML_REGEXP_H__
#if defined(WIN32) && defined(_MSC_VER)
#include <libxml/xmlwin32version.h>
#else
#include <libxml/xmlversion.h>
#endif
#ifdef LIBXML_REGEXP_ENABLED
#include <libxml/tree.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* xmlRegexpPtr:
*
* A libxml regular expression, they can actually be far more complex
* thank the POSIX regex expressions.
*/
typedef struct _xmlRegexp xmlRegexp;
typedef xmlRegexp *xmlRegexpPtr;
/**
* xmlRegExecCtxtPtr:
*
* A libxml progressive regular expression evaluation context
*/
typedef struct _xmlRegExecCtxt xmlRegExecCtxt;
typedef xmlRegExecCtxt *xmlRegExecCtxtPtr;
/*
* The POSIX like API
*/
xmlRegexpPtr xmlRegexpCompile(const xmlChar *regexp);
void xmlRegFreeRegexp(xmlRegexpPtr regexp);
int xmlRegexpExec (xmlRegexpPtr comp,
const xmlChar *value);
void xmlRegexpPrint (FILE *output,
xmlRegexpPtr regexp);
/*
* Callback function when doing a transition in the automata
*/
typedef void (*xmlRegExecCallbacks) (xmlRegExecCtxtPtr exec,
const xmlChar *token,
void *transdata,
void *inputdata);
/*
* The progressive API
*/
xmlRegExecCtxtPtr xmlRegNewExecCtxt (xmlRegexpPtr comp,
xmlRegExecCallbacks callback,
void *data);
void xmlRegFreeExecCtxt (xmlRegExecCtxtPtr exec);
int xmlRegExecPushString (xmlRegExecCtxtPtr exec,
const xmlChar *value,
void *data);
#ifdef __cplusplus
}
#endif
#endif /* LIBXML_REGEXP_ENABLED */
#endif /*__XML_REGEXP_H__ */

105
include/libxml/xmlschemas.h Normal file
View File

@ -0,0 +1,105 @@
/*
* schemas.h : interface to the XML Schemas handling and schema validity
* checking
*
* See Copyright for the status of this software.
*
* Daniel.Veillard@w3.org
*/
#ifndef __XML_SCHEMA_H__
#define __XML_SCHEMA_H__
#if defined(WIN32) && defined(_MSC_VER)
#include <libxml/xmlwin32version.h>
#else
#include <libxml/xmlversion.h>
#endif
#ifdef LIBXML_SCHEMAS_ENABLED
#include <libxml/tree.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
XML_SCHEMAS_ERR_OK = 0,
XML_SCHEMAS_ERR_NOROOT = 1,
XML_SCHEMAS_ERR_UNDECLAREDELEM,
XML_SCHEMAS_ERR_NOTTOPLEVEL,
XML_SCHEMAS_ERR_MISSING,
XML_SCHEMAS_ERR_WRONGELEM,
XML_SCHEMAS_ERR_NOTYPE,
XML_SCHEMAS_ERR_NOROLLBACK,
XML_SCHEMAS_ERR_ISABSTRACT,
XML_SCHEMAS_ERR_NOTEMPTY,
XML_SCHEMAS_ERR_HAVEDEFAULT,
XML_SCHEMAS_ERR_NOTNILLABLE,
XML_SCHEMAS_ERR_EXTRACONTENT,
XML_SCHEMAS_ERR_INVALIDATTR,
XML_SCHEMAS_ERR_INVALIDELEM,
XML_SCHEMAS_ERR_CONSTRUCT,
XML_SCHEMAS_ERR_INTERNAL,
XML_SCHEMAS_ERR_NOTSIMPLE,
XML_SCHEMAS_ERR_ATTRUNKNOWN,
XML_SCHEMAS_ERR_ATTRINVALID,
XML_SCHEMAS_ERR_,
XML_SCHEMAS_ERR_XXX
} xmlSchemaValidError;
/**
* The schemas related types are kept internal
*/
typedef struct _xmlSchema xmlSchema;
typedef xmlSchema *xmlSchemaPtr;
/**
* A schemas validation context
*/
typedef void (*xmlSchemaValidityErrorFunc) (void *ctx, const char *msg, ...);
typedef void (*xmlSchemaValidityWarningFunc) (void *ctx, const char *msg, ...);
typedef struct _xmlSchemaParserCtxt xmlSchemaParserCtxt;
typedef xmlSchemaParserCtxt *xmlSchemaParserCtxtPtr;
typedef struct _xmlSchemaValidCtxt xmlSchemaValidCtxt;
typedef xmlSchemaValidCtxt *xmlSchemaValidCtxtPtr;
/*
* Interfaces for parsing.
*/
xmlSchemaParserCtxtPtr xmlSchemaNewParserCtxt(const char *URL);
void xmlSchemaFreeParserCtxt (xmlSchemaParserCtxtPtr ctxt);
void xmlSchemaSetParserErrors(xmlSchemaParserCtxtPtr ctxt,
xmlSchemaValidityErrorFunc err,
xmlSchemaValidityWarningFunc warn,
void *ctx);
xmlSchemaPtr xmlSchemaParse (xmlSchemaParserCtxtPtr ctxt);
void xmlSchemaFree (xmlSchemaPtr schema);
void xmlSchemaDump (FILE *output,
xmlSchemaPtr schema);
/*
* Interfaces for validating
*/
void xmlSchemaSetValidErrors (xmlSchemaValidCtxtPtr ctxt,
xmlSchemaValidityErrorFunc err,
xmlSchemaValidityWarningFunc warn,
void *ctx);
xmlSchemaValidCtxtPtr xmlSchemaNewValidCtxt (xmlSchemaPtr schema);
void xmlSchemaFreeValidCtxt (xmlSchemaValidCtxtPtr ctxt);
int xmlSchemaValidateDoc (xmlSchemaValidCtxtPtr ctxt,
xmlDocPtr instance);
int xmlSchemaValidateStream (xmlSchemaValidCtxtPtr ctxt,
xmlParserInputBufferPtr input,
xmlCharEncoding enc,
xmlSAXHandlerPtr sax,
void *user_data);
#ifdef __cplusplus
}
#endif
#endif /* LIBXML_SCHEMAS_ENABLED */
#endif /* __XML_SCHEMA_H__ */

View File

@ -0,0 +1,45 @@
/*
* schemastypes.c : interface of the XML Schema Datatypes
* definition and validity checking
*
* See Copyright for the status of this software.
*
* Daniel Veillard <veillard@redhat.com>
*/
#ifndef __XML_SCHEMA_TYPES_H__
#define __XML_SCHEMA_TYPES_H__
#if defined(WIN32) && defined(_MSC_VER)
#include <libxml/xmlwin32version.h>
#else
#include <libxml/xmlversion.h>
#endif
#ifdef LIBXML_SCHEMAS_ENABLED
#include <libxml/schemasInternals.h>
#ifdef __cplusplus
extern "C" {
#endif
void xmlSchemaInitTypes (void);
void xmlSchemaCleanupTypes (void);
xmlSchemaTypePtr xmlSchemaGetPredefinedType (const xmlChar *name,
const xmlChar *ns);
int xmlSchemaValidatePredefinedType (xmlSchemaTypePtr type,
const xmlChar *value,
xmlSchemaValPtr *val);
int xmlSchemaValidateFacet (xmlSchemaTypePtr base,
xmlSchemaFacetPtr facet,
const xmlChar *value,
xmlSchemaValPtr val);
void xmlSchemaFreeValue (xmlSchemaValPtr val);
#ifdef __cplusplus
}
#endif
#endif /* LIBXML_SCHEMAS_ENABLED */
#endif /* __XML_SCHEMA_TYPES_H__ */

164
include/libxml/xmlunicode.h Normal file
View File

@ -0,0 +1,164 @@
/*
* xmlunicode.h: this header exports interfaces for the Unicode character APIs
*
* This file is automatically generated from the
* UCS description files of the Unicode Character Database
* http://www.unicode.org/Public/3.1-Update/UnicodeCharacterDatabase-3.1.0.html
* using the genUnicode.py Python script.
*
* Generation date: Tue Apr 16 17:28:05 2002
* Sources: Blocks-4.txt UnicodeData-3.1.0.txt
* Daniel Veillard <veillard@redhat.com>
*/
#ifndef __XML_UNICODE_H__
#define __XML_UNICODE_H__
#ifdef __cplusplus
extern "C" {
#endif
int xmlUCSIsAlphabeticPresentationForms (int code);
int xmlUCSIsArabic (int code);
int xmlUCSIsArabicPresentationFormsA (int code);
int xmlUCSIsArabicPresentationFormsB (int code);
int xmlUCSIsArmenian (int code);
int xmlUCSIsArrows (int code);
int xmlUCSIsBasicLatin (int code);
int xmlUCSIsBengali (int code);
int xmlUCSIsBlockElements (int code);
int xmlUCSIsBopomofo (int code);
int xmlUCSIsBopomofoExtended (int code);
int xmlUCSIsBoxDrawing (int code);
int xmlUCSIsBraillePatterns (int code);
int xmlUCSIsByzantineMusicalSymbols (int code);
int xmlUCSIsCJKCompatibility (int code);
int xmlUCSIsCJKCompatibilityForms (int code);
int xmlUCSIsCJKCompatibilityIdeographs (int code);
int xmlUCSIsCJKCompatibilityIdeographsSupplement (int code);
int xmlUCSIsCJKRadicalsSupplement (int code);
int xmlUCSIsCJKSymbolsandPunctuation (int code);
int xmlUCSIsCJKUnifiedIdeographs (int code);
int xmlUCSIsCJKUnifiedIdeographsExtensionA (int code);
int xmlUCSIsCJKUnifiedIdeographsExtensionB (int code);
int xmlUCSIsCherokee (int code);
int xmlUCSIsCombiningDiacriticalMarks (int code);
int xmlUCSIsCombiningHalfMarks (int code);
int xmlUCSIsCombiningMarksforSymbols (int code);
int xmlUCSIsControlPictures (int code);
int xmlUCSIsCurrencySymbols (int code);
int xmlUCSIsCyrillic (int code);
int xmlUCSIsDeseret (int code);
int xmlUCSIsDevanagari (int code);
int xmlUCSIsDingbats (int code);
int xmlUCSIsEnclosedAlphanumerics (int code);
int xmlUCSIsEnclosedCJKLettersandMonths (int code);
int xmlUCSIsEthiopic (int code);
int xmlUCSIsGeneralPunctuation (int code);
int xmlUCSIsGeometricShapes (int code);
int xmlUCSIsGeorgian (int code);
int xmlUCSIsGothic (int code);
int xmlUCSIsGreek (int code);
int xmlUCSIsGreekExtended (int code);
int xmlUCSIsGujarati (int code);
int xmlUCSIsGurmukhi (int code);
int xmlUCSIsHalfwidthandFullwidthForms (int code);
int xmlUCSIsHangulCompatibilityJamo (int code);
int xmlUCSIsHangulJamo (int code);
int xmlUCSIsHangulSyllables (int code);
int xmlUCSIsHebrew (int code);
int xmlUCSIsHighPrivateUseSurrogates (int code);
int xmlUCSIsHighSurrogates (int code);
int xmlUCSIsHiragana (int code);
int xmlUCSIsIPAExtensions (int code);
int xmlUCSIsIdeographicDescriptionCharacters (int code);
int xmlUCSIsKanbun (int code);
int xmlUCSIsKangxiRadicals (int code);
int xmlUCSIsKannada (int code);
int xmlUCSIsKatakana (int code);
int xmlUCSIsKhmer (int code);
int xmlUCSIsLao (int code);
int xmlUCSIsLatin1Supplement (int code);
int xmlUCSIsLatinExtendedA (int code);
int xmlUCSIsLatinExtendedB (int code);
int xmlUCSIsLatinExtendedAdditional (int code);
int xmlUCSIsLetterlikeSymbols (int code);
int xmlUCSIsLowSurrogates (int code);
int xmlUCSIsMalayalam (int code);
int xmlUCSIsMathematicalAlphanumericSymbols (int code);
int xmlUCSIsMathematicalOperators (int code);
int xmlUCSIsMiscellaneousSymbols (int code);
int xmlUCSIsMiscellaneousTechnical (int code);
int xmlUCSIsMongolian (int code);
int xmlUCSIsMusicalSymbols (int code);
int xmlUCSIsMyanmar (int code);
int xmlUCSIsNumberForms (int code);
int xmlUCSIsOgham (int code);
int xmlUCSIsOldItalic (int code);
int xmlUCSIsOpticalCharacterRecognition (int code);
int xmlUCSIsOriya (int code);
int xmlUCSIsPrivateUse (int code);
int xmlUCSIsRunic (int code);
int xmlUCSIsSinhala (int code);
int xmlUCSIsSmallFormVariants (int code);
int xmlUCSIsSpacingModifierLetters (int code);
int xmlUCSIsSpecials (int code);
int xmlUCSIsSuperscriptsandSubscripts (int code);
int xmlUCSIsSyriac (int code);
int xmlUCSIsTags (int code);
int xmlUCSIsTamil (int code);
int xmlUCSIsTelugu (int code);
int xmlUCSIsThaana (int code);
int xmlUCSIsThai (int code);
int xmlUCSIsTibetan (int code);
int xmlUCSIsUnifiedCanadianAboriginalSyllabics (int code);
int xmlUCSIsYiRadicals (int code);
int xmlUCSIsYiSyllables (int code);
int xmlUCSIsBlock (int code,
const char *block);
int xmlUCSIsCatC (int code);
int xmlUCSIsCatCc (int code);
int xmlUCSIsCatCf (int code);
int xmlUCSIsCatCo (int code);
int xmlUCSIsCatCs (int code);
int xmlUCSIsCatL (int code);
int xmlUCSIsCatLl (int code);
int xmlUCSIsCatLm (int code);
int xmlUCSIsCatLo (int code);
int xmlUCSIsCatLt (int code);
int xmlUCSIsCatLu (int code);
int xmlUCSIsCatM (int code);
int xmlUCSIsCatMc (int code);
int xmlUCSIsCatMe (int code);
int xmlUCSIsCatMn (int code);
int xmlUCSIsCatN (int code);
int xmlUCSIsCatNd (int code);
int xmlUCSIsCatNl (int code);
int xmlUCSIsCatNo (int code);
int xmlUCSIsCatP (int code);
int xmlUCSIsCatPc (int code);
int xmlUCSIsCatPd (int code);
int xmlUCSIsCatPe (int code);
int xmlUCSIsCatPf (int code);
int xmlUCSIsCatPi (int code);
int xmlUCSIsCatPo (int code);
int xmlUCSIsCatPs (int code);
int xmlUCSIsCatS (int code);
int xmlUCSIsCatSc (int code);
int xmlUCSIsCatSk (int code);
int xmlUCSIsCatSm (int code);
int xmlUCSIsCatSo (int code);
int xmlUCSIsCatZ (int code);
int xmlUCSIsCatZl (int code);
int xmlUCSIsCatZp (int code);
int xmlUCSIsCatZs (int code);
int xmlUCSIsCat (int code,
const char *cat);
#ifdef __cplusplus
}
#endif
#endif /* __XML_UNICODE_H__ */

View File

@ -189,6 +189,42 @@ extern void xmlCheckVersion(int version);
#define DEBUG_MEMORY_LOCATION
#endif
/**
* LIBXML_UNICODE_ENABLED
*
* Whether the Unicode related interfaces are compiled in
*/
#if @WITH_SCHEMAS@
#define LIBXML_UNICODE_ENABLED
#endif
/**
* LIBXML_REGEXP_ENABLED
*
* Whether the regular expressions interfaces are compiled in
*/
#if @WITH_SCHEMAS@
#define LIBXML_REGEXP_ENABLED
#endif
/**
* LIBXML_AUTOMATA_ENABLED
*
* Whether the automata interfaces are compiled in
*/
#if @WITH_SCHEMAS@
#define LIBXML_AUTOMATA_ENABLED
#endif
/**
* LIBXML_SCHEMAS_ENABLED
*
* Whether the Schemas validation interfaces are compiled in
*/
#if @WITH_SCHEMAS@
#define LIBXML_SCHEMAS_ENABLED
#endif
/**
* LIBXML_DLL_IMPORT:
*

4
result/automata/a Normal file
View File

@ -0,0 +1,4 @@
=> Passed
=> Failed
=> Failed
=> Failed

6
result/automata/aba Normal file
View File

@ -0,0 +1,6 @@
=> Passed
=> Passed
=> Passed
=> Failed
=> Failed
=> Failed

5
result/automata/abaa Normal file
View File

@ -0,0 +1,5 @@
=> Passed
=> Passed
=> Passed
=> Failed
=> Failed

4
result/automata/abba Normal file
View File

@ -0,0 +1,4 @@
=> Passed
=> Passed
=> Failed
=> Failed

2
result/automata/po Normal file
View File

@ -0,0 +1,2 @@
=> Passed
=> Passed

12
result/regexp/content Normal file
View File

@ -0,0 +1,12 @@
Regexp: ((a|b|c)def)
adef: Ok
bdef: Ok
adefg: Fail
aaef: Fail
Regexp: ((a|b|c|d|e|f)?(g|h|i)+(k|l)*)
g: Ok
gi: Ok
fil: Ok
gikl: Ok
cghhhiill: Ok
ak: Fail

7
result/regexp/hard Normal file
View File

@ -0,0 +1,7 @@
Regexp: ((a|b|\p{Nd}){1,2}|aaa|bbbb){1,2}
bab: Ok
aaca: Fail
aaabbbb: Ok
a0b: Ok
aa0aaa: Fail
b0aaa: Ok

6
result/regexp/ncname Normal file
View File

@ -0,0 +1,6 @@
Regexp: [\i-[:]][\c-[:]]*
a: Ok
abc: Ok
abc1d: Ok
1ac: Fail
a1b:c: Fail

15
result/regexp/ranges Normal file
View File

@ -0,0 +1,15 @@
Regexp: a{2,3}
a: Fail
aa: Ok
aaa: Ok
aaaa: Fail
Regexp: ba{2,3}c
bac: Fail
baac: Ok
baaac: Ok
baaaac: Fail
Regexp: a(b|c){2,3}d
abcd: Ok
acccd: Ok
abd: Fail
accccd: Fail

32
result/regexp/xpath Normal file
View File

@ -0,0 +1,32 @@
Regexp: (\.//)?(((child::)?((\i\c*:)?(\i\c*|\*)))|\.)(/(((child::)?((\i\c*:)?(\i\c*|\*)))|\.))*(\|(\.//)?(((child::)?((\i\c*:)?(\i\c*|\*)))|\.)(/(((child::)?((\i\c*:)?(\i\c*|\*)))|\.))*)*
a: Ok
a12/b312/b312/b312/b312/b312/b312/b312/b312/b312/b312/b312/b3: Ok
*: Ok
a|b: Ok
.//a:b: Ok
a/b/c: Ok
a/*/b: Ok
a:*/b:*/c:*: Ok
child::a/child::b:*: Ok
child::a/child::b:*|a/*/b|.//a:b: Ok
1: Fail
1ab: Fail
a:1: Ok
@a: Fail
ancestor::a: Ok
Regexp: (\.//)?(((child::)?(([\i-[:]][\c-[:]]*:)?([\i-[:]][\c-[:]]*|\*)))|\.)(/(((child::)?(([\i-[:]][\c-[:]]*:)?([\i-[:]][\c-[:]]*|\*)))|\.))*(\|(\.//)?(((child::)?(([\i-[:]][\c-[:]]*:)?([\i-[:]][\c-[:]]*|\*)))|\.)(/(((child::)?(([\i-[:]][\c-[:]]*:)?([\i-[:]][\c-[:]]*|\*)))|\.))*)*
a: Ok
a12/b312/b312/b312/b312/b312/b312/b312/b312/b312/b312/b312/b3: Ok
*: Ok
a|b: Ok
.//a:b: Ok
a/b/c: Ok
a/*/b: Ok
a:*/b:*/c:*: Ok
child::a/child::b:*: Ok
child::a/child::b:*|a/*/b|.//a:b: Ok
1: Fail
1ab: Fail
a:1: Fail
@a: Fail
ancestor::a: Fail

0
result/schemas/po Normal file
View File

14
test/automata/a Normal file
View File

@ -0,0 +1,14 @@
#
# tests just "a"
#
t 0 1 a
f 1
-------
a
=>
a
a
=>
=>
b
=>

26
test/automata/aba Normal file
View File

@ -0,0 +1,26 @@
#
# Tests a[ab]*
#
t 0 1 a
t 1 1 a
t 1 1 b
f 1
-------
a
=>
a
a
=>
a
b
a
b
a
b
=>
b
=>
a
c
=>
=>

43
test/automata/abaa Normal file
View File

@ -0,0 +1,43 @@
#
# Tests: a[ab]*a{2,3}
#
t 0 1 a
t 1 1 a
t 1 1 b
c 1 2 2 3 a
f 2
-------
a
a
a
=>
# Pass
a
b
a
a
=>
# Pass
a
a
a
a
a
a
a
a
a
=>
# Pass
a
b
a
=>
# Fail
a
b
a
a
b
=>
# Fail

30
test/automata/abba Normal file
View File

@ -0,0 +1,30 @@
#
# Tests ab*a with an eliminated epsilon transition
#
t 0 1 a
t 1 2 b
e 1 2
t 2 2 b
t 2 3 a
f 3
-------
a
a
=>
# Pass
a
b
b
a
=>
# Pass
a
b
=>
# Fail
a
b
a
b
=>
# Fail

19
test/automata/po Normal file
View File

@ -0,0 +1,19 @@
#
# purchaseOrder
#
t 0 1 shipTo
t 1 2 billTo
t 2 3 comment
t 3 4 items
e 2 3
f 4
-------
shipTo
billTo
comment
items
=>
shipTo
billTo
items
=>

12
test/regexp/content Normal file
View File

@ -0,0 +1,12 @@
=>((a|b|c)def)
adef
bdef
adefg
aaef
=>((a|b|c|d|e|f)?(g|h|i)+(k|l)*)
g
gi
fil
gikl
cghhhiill
ak

7
test/regexp/hard Normal file
View File

@ -0,0 +1,7 @@
=>((a|b|\p{Nd}){1,2}|aaa|bbbb){1,2}
bab
aaca
aaabbbb
a0b
aa0aaa
b0aaa

6
test/regexp/ncname Normal file
View File

@ -0,0 +1,6 @@
=>[\i-[:]][\c-[:]]*
a
abc
abc1d
1ac
a1b:c

15
test/regexp/ranges Normal file
View File

@ -0,0 +1,15 @@
=>a{2,3}
a
aa
aaa
aaaa
=>ba{2,3}c
bac
baac
baaac
baaaac
=>a(b|c){2,3}d
abcd
acccd
abd
accccd

37
test/regexp/xpath Normal file
View File

@ -0,0 +1,37 @@
=>(\.//)?(((child::)?((\i\c*:)?(\i\c*|\*)))|\.)(/(((child::)?((\i\c*:)?(\i\c*|\*)))|\.))*(\|(\.//)?(((child::)?((\i\c*:)?(\i\c*|\*)))|\.)(/(((child::)?((\i\c*:)?(\i\c*|\*)))|\.))*)*
a
a12/b312/b312/b312/b312/b312/b312/b312/b312/b312/b312/b312/b3
*
a|b
.//a:b
a/b/c
a/*/b
a:*/b:*/c:*
child::a/child::b:*
child::a/child::b:*|a/*/b|.//a:b
1
1ab
a:1
@a
ancestor::a
#
# the previous regexp from the Schemas for Schemas was broken
# here is the fixed one:
# http://lists.w3.org/Archives/Public/www-xml-schema-comments/2002AprJun/0005.html
#
=>(\.//)?(((child::)?(([\i-[:]][\c-[:]]*:)?([\i-[:]][\c-[:]]*|\*)))|\.)(/(((child::)?(([\i-[:]][\c-[:]]*:)?([\i-[:]][\c-[:]]*|\*)))|\.))*(\|(\.//)?(((child::)?(([\i-[:]][\c-[:]]*:)?([\i-[:]][\c-[:]]*|\*)))|\.)(/(((child::)?(([\i-[:]][\c-[:]]*:)?([\i-[:]][\c-[:]]*|\*)))|\.))*)*
a
a12/b312/b312/b312/b312/b312/b312/b312/b312/b312/b312/b312/b3
*
a|b
.//a:b
a/b/c
a/*/b
a:*/b:*/c:*
child::a/child::b:*
child::a/child::b:*|a/*/b|.//a:b
1
1ab
a:1
@a
ancestor::a

32
test/schemas/po.xml Normal file
View File

@ -0,0 +1,32 @@
<?xml version="1.0"?>
<purchaseOrder orderDate="1999-10-20">
<shipTo country="US">
<name>Alice Smith</name>
<street>123 Maple Street</street>
<city>Mill Valley</city>
<state>CA</state>
<zip>90952</zip>
</shipTo>
<billTo country="US">
<name>Robert Smith</name>
<street>8 Oak Avenue</street>
<city>Old Town</city>
<state>PA</state>
<zip>95819</zip>
</billTo>
<comment>Hurry, my lawn is going wild!</comment>
<items>
<item partNum="872-AA">
<productName>Lawnmower</productName>
<quantity>1</quantity>
<USPrice>148.95</USPrice>
<comment>Confirm this is electric</comment>
</item>
<item partNum="926-AA">
<productName>Baby Monitor</productName>
<quantity>1</quantity>
<USPrice>39.98</USPrice>
<shipDate>1999-05-21</shipDate>
</item>
</items>
</purchaseOrder>

59
test/schemas/po.xsd Normal file
View File

@ -0,0 +1,59 @@
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:annotation>
<xsd:documentation xml:lang="en">
Purchase order schema for Example.com.
Copyright 2000 Example.com. All rights reserved.
</xsd:documentation>
</xsd:annotation>
<xsd:element name="purchaseOrder" type="PurchaseOrderType"/>
<xsd:element name="comment" type="xsd:string"/>
<xsd:complexType name="PurchaseOrderType">
<xsd:sequence>
<xsd:element name="shipTo" type="USAddress"/>
<xsd:element name="billTo" type="USAddress"/>
<xsd:element ref="comment" minOccurs="0"/>
<xsd:element name="items" type="Items"/>
</xsd:sequence>
<xsd:attribute name="orderDate" type="xsd:date"/>
</xsd:complexType>
<xsd:complexType name="USAddress">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="street" type="xsd:string"/>
<xsd:element name="city" type="xsd:string"/>
<xsd:element name="state" type="xsd:string"/>
<xsd:element name="zip" type="xsd:decimal"/>
</xsd:sequence>
<xsd:attribute name="country" type="xsd:NMTOKEN" fixed="US"/>
</xsd:complexType>
<xsd:complexType name="Items">
<xsd:sequence>
<xsd:element name="item" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="productName" type="xsd:string"/>
<xsd:element name="quantity">
<xsd:simpleType>
<xsd:restriction base="xsd:positiveInteger">
<xsd:maxExclusive value="100"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="USPrice" type="xsd:decimal"/>
<xsd:element ref="comment" minOccurs="0"/>
<xsd:element name="shipDate" type="xsd:date" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="partNum" type="SKU" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<!-- Stock Keeping Unit, a code for identifying products -->
<xsd:simpleType name="SKU">
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{3}-[A-Z]{2}"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>

306
testAutomata.c Normal file
View File

@ -0,0 +1,306 @@
/*
* testRegexp.c: simple module for testing regular expressions
*
* See Copyright for the status of this software.
*
* Daniel Veillard <veillard@redhat.com>
*/
#include <string.h>
#include "libxml.h"
#ifdef LIBXML_AUTOMATA_ENABLED
#include <libxml/xmlautomata.h>
static int scanNumber(char **ptr) {
int ret = 0;
char *cur;
cur = *ptr;
while ((*cur >= '0') && (*cur <= '9')) {
ret = ret * 10 + (*cur - '0');
cur++;
}
*ptr = cur;
return(ret);
}
static void
testRegexpFile(const char *filename) {
FILE *input;
char exp[5000];
int len;
int ret;
int i;
xmlAutomataPtr am;
xmlAutomataStatePtr states[1000];
xmlRegexpPtr regexp = NULL;
xmlRegExecCtxtPtr exec;
for (i = 0;i<1000;i++)
states[i] = NULL;
input = fopen(filename, "r");
if (input == NULL) {
xmlGenericError(xmlGenericErrorContext,
"Cannot open %s for reading\n", filename);
return;
}
am = xmlNewAutomata();
if (am == NULL) {
xmlGenericError(xmlGenericErrorContext,
"Cannot create automata\n");
fclose(input);
}
states[0] = xmlAutomataGetInitState(am);
if (states[0] == NULL) {
xmlGenericError(xmlGenericErrorContext,
"Cannot get start state\n");
xmlFreeAutomata(am);
fclose(input);
}
ret = 0;
while (fgets(exp, 4500, input) != NULL) {
if (exp[0] == '#')
continue;
len = strlen(exp);
len--;
while ((len >= 0) &&
((exp[len] == '\n') || (exp[len] == '\t') ||
(exp[len] == '\r') || (exp[len] == ' '))) len--;
exp[len + 1] = 0;
if (len >= 0) {
if ((am != NULL) && (exp[0] == 't') && (exp[1] == ' ')) {
char *ptr = &exp[2];
int from, to;
from = scanNumber(&ptr);
if (*ptr != ' ') {
xmlGenericError(xmlGenericErrorContext,
"Bad line %s\n", exp);
break;
}
if (states[from] == NULL)
states[from] = xmlAutomataNewState(am);
ptr++;
to = scanNumber(&ptr);
if (*ptr != ' ') {
xmlGenericError(xmlGenericErrorContext,
"Bad line %s\n", exp);
break;
}
if (states[to] == NULL)
states[to] = xmlAutomataNewState(am);
ptr++;
xmlAutomataNewTransition(am, states[from], states[to],
BAD_CAST ptr, NULL);
} else if ((am != NULL) && (exp[0] == 'e') && (exp[1] == ' ')) {
char *ptr = &exp[2];
int from, to;
from = scanNumber(&ptr);
if (*ptr != ' ') {
xmlGenericError(xmlGenericErrorContext,
"Bad line %s\n", exp);
break;
}
if (states[from] == NULL)
states[from] = xmlAutomataNewState(am);
ptr++;
to = scanNumber(&ptr);
if (states[to] == NULL)
states[to] = xmlAutomataNewState(am);
xmlAutomataNewEpsilon(am, states[from], states[to]);
} else if ((am != NULL) && (exp[0] == 'f') && (exp[1] == ' ')) {
char *ptr = &exp[2];
int state;
state = scanNumber(&ptr);
if (states[state] == NULL) {
xmlGenericError(xmlGenericErrorContext,
"Bad state %d : %s\n", state, exp);
break;
}
xmlAutomataSetFinalState(am, states[state]);
} else if ((am != NULL) && (exp[0] == 'c') && (exp[1] == ' ')) {
char *ptr = &exp[2];
int from, to;
int min, max;
from = scanNumber(&ptr);
if (*ptr != ' ') {
xmlGenericError(xmlGenericErrorContext,
"Bad line %s\n", exp);
break;
}
if (states[from] == NULL)
states[from] = xmlAutomataNewState(am);
ptr++;
to = scanNumber(&ptr);
if (*ptr != ' ') {
xmlGenericError(xmlGenericErrorContext,
"Bad line %s\n", exp);
break;
}
if (states[to] == NULL)
states[to] = xmlAutomataNewState(am);
ptr++;
min = scanNumber(&ptr);
if (*ptr != ' ') {
xmlGenericError(xmlGenericErrorContext,
"Bad line %s\n", exp);
break;
}
ptr++;
max = scanNumber(&ptr);
if (*ptr != ' ') {
xmlGenericError(xmlGenericErrorContext,
"Bad line %s\n", exp);
break;
}
ptr++;
xmlAutomataNewCountTrans(am, states[from], states[to],
BAD_CAST ptr, min, max, NULL);
} else if ((am != NULL) && (exp[0] == '-') && (exp[1] == '-')) {
/* end of the automata */
regexp = xmlAutomataCompile(am);
xmlFreeAutomata(am);
am = NULL;
if (regexp == NULL) {
xmlGenericError(xmlGenericErrorContext,
"Failed to compile the automata");
break;
}
} else if ((exp[0] == '=') && (exp[1] == '>')) {
if (regexp == NULL) {
printf("=> failed not compiled\n");
} else {
if (exec == NULL)
exec = xmlRegNewExecCtxt(regexp, NULL, NULL);
if (ret == 0) {
ret = xmlRegExecPushString(exec, NULL, NULL);
}
if (ret == 1)
printf("=> Passed\n");
else if ((ret == 0) || (ret == -1))
printf("=> Failed\n");
else if (ret < 0)
printf("=> Error\n");
xmlRegFreeExecCtxt(exec);
exec = NULL;
}
ret = 0;
} else if (regexp != NULL) {
if (exec == NULL)
exec = xmlRegNewExecCtxt(regexp, NULL, NULL);
ret = xmlRegExecPushString(exec, BAD_CAST exp, NULL);
} else {
xmlGenericError(xmlGenericErrorContext,
"Unexpected line %s\n", exp);
}
}
}
fclose(input);
if (regexp != NULL)
xmlRegFreeRegexp(regexp);
if (exec != NULL)
xmlRegFreeExecCtxt(exec);
if (am != NULL)
xmlFreeAutomata(am);
}
int main(int argc, char **argv) {
xmlInitMemory();
if (argc == 1) {
int ret;
xmlAutomataPtr am;
xmlAutomataStatePtr start, cur;
xmlRegexpPtr regexp;
xmlRegExecCtxtPtr exec;
am = xmlNewAutomata();
start = xmlAutomataGetInitState(am);
/* generate a[ba]*a */
cur = xmlAutomataNewTransition(am, start, NULL, BAD_CAST"a", NULL);
xmlAutomataNewTransition(am, cur, cur, BAD_CAST"b", NULL);
xmlAutomataNewTransition(am, cur, cur, BAD_CAST"a", NULL);
cur = xmlAutomataNewCountTrans(am, cur, NULL, BAD_CAST"a", 2, 3, NULL);
xmlAutomataSetFinalState(am, cur);
/* compile it in a regexp and free the automata */
regexp = xmlAutomataCompile(am);
xmlFreeAutomata(am);
/* test the regexp */
xmlRegexpPrint(stdout, regexp);
exec = xmlRegNewExecCtxt(regexp, NULL, NULL);
ret = xmlRegExecPushString(exec, BAD_CAST"a", NULL);
if (ret == 1)
printf("final\n");
else if (ret < 0)
printf("error\n");
ret =xmlRegExecPushString(exec, BAD_CAST"a", NULL);
if (ret == 1)
printf("final\n");
else if (ret < 0)
printf("error\n");
ret =xmlRegExecPushString(exec, BAD_CAST"b", NULL);
if (ret == 1)
printf("final\n");
else if (ret < 0)
printf("error\n");
ret =xmlRegExecPushString(exec, BAD_CAST"a", NULL);
if (ret == 1)
printf("final\n");
else if (ret < 0)
printf("error\n");
ret =xmlRegExecPushString(exec, BAD_CAST"a", NULL);
if (ret == 1)
printf("final\n");
else if (ret < 0)
printf("error\n");
ret =xmlRegExecPushString(exec, BAD_CAST"a", NULL);
if (ret == 1)
printf("final\n");
else if (ret < 0)
printf("error\n");
ret =xmlRegExecPushString(exec, BAD_CAST"a", NULL);
if (ret == 1)
printf("final\n");
else if (ret < 0)
printf("error\n");
if (ret == 0) {
ret = xmlRegExecPushString(exec, NULL, NULL);
if (ret == 1)
printf("final\n");
else if (ret < 0)
printf("error\n");
}
xmlRegFreeExecCtxt(exec);
/* free the regexp */
xmlRegFreeRegexp(regexp);
} else {
int i;
for (i = 1;i < argc;i++)
testRegexpFile(argv[i]);
}
xmlCleanupParser();
xmlMemoryDump();
return(0);
}
#else
#include <stdio.h>
int main(int argc, char **argv) {
printf("%s : Automata support not compiled in\n", argv[0]);
return(0);
}
#endif /* LIBXML_AUTOMATA_ENABLED */

157
testRegexp.c Normal file
View File

@ -0,0 +1,157 @@
/*
* testRegexp.c: simple module for testing regular expressions
*
* See Copyright for the status of this software.
*
* Daniel Veillard <veillard@redhat.com>
*/
#include <string.h>
#include "libxml.h"
#ifdef LIBXML_REGEXP_ENABLED
#include <libxml/tree.h>
#include <libxml/xmlregexp.h>
int repeat = 0;
int debug = 0;
static void testRegexp(xmlRegexpPtr comp, const char *value) {
int ret;
ret = xmlRegexpExec(comp, (const xmlChar *) value);
if (ret == 1)
printf("%s: Ok\n", value);
else if (ret == 0)
printf("%s: Fail\n", value);
else
printf("%s: Error: %d\n", value, ret);
if (repeat) {
int j;
for (j = 0;j < 999999;j++)
xmlRegexpExec(comp, (const xmlChar *) value);
}
}
static void
testRegexpFile(const char *filename) {
xmlRegexpPtr comp = NULL;
FILE *input;
char expression[5000];
int len;
input = fopen(filename, "r");
if (input == NULL) {
xmlGenericError(xmlGenericErrorContext,
"Cannot open %s for reading\n", filename);
return;
}
while (fgets(expression, 4500, input) != NULL) {
len = strlen(expression);
len--;
while ((len >= 0) &&
((expression[len] == '\n') || (expression[len] == '\t') ||
(expression[len] == '\r') || (expression[len] == ' '))) len--;
expression[len + 1] = 0;
if (len >= 0) {
if (expression[0] == '#')
continue;
if ((expression[0] == '=') && (expression[1] == '>')) {
char *pattern = &expression[2];
if (comp != NULL) {
xmlRegFreeRegexp(comp);
comp = NULL;
}
printf("Regexp: %s\n", pattern) ;
comp = xmlRegexpCompile((const xmlChar *) pattern);
if (comp == NULL) {
printf(" failed to compile\n");
break;
}
} else if (comp == NULL) {
printf("Regexp: %s\n", expression) ;
comp = xmlRegexpCompile((const xmlChar *) expression);
if (comp == NULL) {
printf(" failed to compile\n");
break;
}
} else if (comp != NULL) {
testRegexp(comp, expression);
}
}
}
fclose(input);
if (comp != NULL)
xmlRegFreeRegexp(comp);
}
static void usage(const char *name) {
fprintf(stderr, "Usage: %s\n", name);
}
int main(int argc, char **argv) {
xmlRegexpPtr comp = NULL;
const char *pattern = NULL;
char *filename = NULL;
int i;
xmlInitMemory();
if (argc <= 1) {
usage(argv[0]);
return(1);
}
for (i = 1; i < argc ; i++) {
if (!strcmp(argv[i], "-"))
break;
if (argv[i][0] != '-')
continue;
if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) {
debug++;
} else if ((!strcmp(argv[i], "-repeat")) ||
(!strcmp(argv[i], "--repeat"))) {
repeat++;
} else if ((!strcmp(argv[i], "-i")) || (!strcmp(argv[i], "--input")))
filename = argv[++i];
else {
fprintf(stderr, "Unknown option %s\n", argv[i]);
usage(argv[0]);
}
}
if (filename != NULL) {
testRegexpFile(filename);
} else {
for (i = 1; i < argc ; i++) {
if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) {
if (pattern == NULL) {
pattern = argv[i];
printf("Testing %s:\n", pattern);
comp = xmlRegexpCompile((const xmlChar *) pattern);
if (comp == NULL) {
printf(" failed to compile\n");
break;
}
if (debug)
xmlRegexpPrint(stdout, comp);
} else {
testRegexp(comp, argv[i]);
}
}
}
if (comp != NULL)
xmlRegFreeRegexp(comp);
}
xmlCleanupParser();
xmlMemoryDump();
return(0);
}
#else
#include <stdio.h>
int main(int argc, char **argv) {
printf("%s : Regexp support not compiled in\n", argv[0]);
return(0);
}
#endif /* LIBXML_REGEXP_ENABLED */

120
testSchemas.c Normal file
View File

@ -0,0 +1,120 @@
/*
* testSchemas.c : a small tester program for Schema validation
*
* See Copyright for the status of this software.
*
* Daniel.Veillard@w3.org
*/
#include "libxml.h"
#ifdef LIBXML_SCHEMAS_ENABLED
#include <libxml/xmlversion.h>
#include <libxml/parser.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <libxml/xmlmemory.h>
#include <libxml/debugXML.h>
#include <libxml/xmlschemas.h>
#ifdef LIBXML_DEBUG_ENABLED
static int debug = 0;
#endif
static int noout = 0;
int main(int argc, char **argv) {
int i;
int files = 0;
xmlSchemaPtr schema = NULL;
for (i = 1; i < argc ; i++) {
if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
debug++;
else
if ((!strcmp(argv[i], "-noout")) || (!strcmp(argv[i], "--noout"))) {
noout++;
}
}
xmlLineNumbersDefault(1);
for (i = 1; i < argc ; i++) {
if (argv[i][0] != '-') {
if (schema == NULL) {
xmlSchemaParserCtxtPtr ctxt;
ctxt = xmlSchemaNewParserCtxt(argv[i]);
xmlSchemaSetParserErrors(ctxt,
(xmlSchemaValidityErrorFunc) fprintf,
(xmlSchemaValidityWarningFunc) fprintf,
stderr);
schema = xmlSchemaParse(ctxt);
xmlSchemaFreeParserCtxt(ctxt);
if (debug)
xmlSchemaDump(stdout, schema);
} else {
xmlDocPtr doc;
doc = xmlParseFile(argv[i]);
if (doc == NULL) {
fprintf(stderr, "Could not parse %s\n", argv[i]);
} else {
xmlSchemaValidCtxtPtr ctxt;
int ret;
ctxt = xmlSchemaNewValidCtxt(schema);
xmlSchemaSetValidErrors(ctxt,
(xmlSchemaValidityErrorFunc) fprintf,
(xmlSchemaValidityWarningFunc) fprintf,
stderr);
ret = xmlSchemaValidateDoc(ctxt, doc);
xmlSchemaFreeValidCtxt(ctxt);
xmlFreeDoc(doc);
}
}
files ++;
}
}
if (schema != NULL)
xmlSchemaFree(schema);
if (files == 0) {
printf("Usage : %s [--debug] [--noout] schemas XMLfiles ...\n",
argv[0]);
printf("\tParse the HTML files and output the result of the parsing\n");
printf("\t--debug : dump a debug tree of the in-memory document\n");
printf("\t--noout : do not print the result\n");
}
xmlSchemaCleanupTypes();
xmlCleanupParser();
xmlMemoryDump();
return(0);
}
#else
#include <stdio.h>
int main(int argc, char **argv) {
printf("%s : Schemas support not compiled in\n", argv[0]);
return(0);
}
#endif /* LIBXML_SCHEMAS_ENABLED */

3470
xmlregexp.c Normal file

File diff suppressed because it is too large Load Diff

4941
xmlschemas.c Normal file

File diff suppressed because it is too large Load Diff

490
xmlschemastypes.c Normal file
View File

@ -0,0 +1,490 @@
/*
* schemastypes.c : implementation of the XML Schema Datatypes
* definition and validity checking
*
* See Copyright for the status of this software.
*
* Daniel Veillard <veillard@redhat.com>
*/
#define IN_LIBXML
#include "libxml.h"
#ifdef LIBXML_SCHEMAS_ENABLED
#include <string.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
#include <libxml/hash.h>
#include <libxml/valid.h>
#include <libxml/xmlschemas.h>
#include <libxml/schemasInternals.h>
#include <libxml/xmlschemastypes.h>
#define DEBUG
#define TODO \
xmlGenericError(xmlGenericErrorContext, \
"Unimplemented block at %s:%d\n", \
__FILE__, __LINE__);
#define XML_SCHEMAS_NAMESPACE_NAME \
(const xmlChar *)"http://www.w3.org/2001/XMLSchema"
typedef enum {
XML_SCHEMAS_UNKNOWN = 0,
XML_SCHEMAS_STRING,
XML_SCHEMAS_NMTOKEN,
XML_SCHEMAS_DECIMAL,
XML_SCHEMAS_,
XML_SCHEMAS_XXX
} xmlSchemaValType;
unsigned long powten[10] = {
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000L,
100000000L, 1000000000L
};
typedef struct _xmlSchemaValDecimal xmlSchemaValDecimal;
typedef xmlSchemaValDecimal *xmlSchemaValDecimalPtr;
struct _xmlSchemaValDecimal {
/* would use long long but not portable */
unsigned long base;
unsigned int extra;
int sign:1;
int frac:7;
int total:8;
};
struct _xmlSchemaVal {
xmlSchemaValType type;
union {
xmlSchemaValDecimal decimal;
} value;
};
static int xmlSchemaTypesInitialized = 0;
static xmlHashTablePtr xmlSchemaTypesBank = NULL;
static xmlSchemaTypePtr xmlSchemaTypeStringDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeAnyTypeDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeAnySimpleTypeDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeDecimalDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeDateDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypePositiveIntegerDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNonNegativeIntegerDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNmtoken = NULL;
/*
* xmlSchemaInitBasicType:
* @name: the type name
*
* Initialize one default type
*/
static xmlSchemaTypePtr
xmlSchemaInitBasicType(const char *name) {
xmlSchemaTypePtr ret;
ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType));
if (ret == NULL) {
xmlGenericError(xmlGenericErrorContext,
"Could not initilize type %s: out of memory\n", name);
return(NULL);
}
memset(ret, 0, sizeof(xmlSchemaType));
ret->name = xmlStrdup((const xmlChar *)name);
ret->type = XML_SCHEMA_TYPE_BASIC;
ret->contentType = XML_SCHEMA_CONTENT_BASIC;
xmlHashAddEntry2(xmlSchemaTypesBank, ret->name,
XML_SCHEMAS_NAMESPACE_NAME, ret);
return(ret);
}
/*
* xmlSchemaInitTypes:
*
* Initialize the default XML Schemas type library
*/
void
xmlSchemaInitTypes(void) {
if (xmlSchemaTypesInitialized != 0)
return;
xmlSchemaTypesBank = xmlHashCreate(40);
xmlSchemaTypeStringDef = xmlSchemaInitBasicType("string");
xmlSchemaTypeAnyTypeDef = xmlSchemaInitBasicType("anyType");
xmlSchemaTypeAnySimpleTypeDef = xmlSchemaInitBasicType("anySimpleType");
xmlSchemaTypeDecimalDef = xmlSchemaInitBasicType("decimal");
xmlSchemaTypeDateDef = xmlSchemaInitBasicType("date");
xmlSchemaTypePositiveIntegerDef = xmlSchemaInitBasicType("positiveInteger");
xmlSchemaTypeNonNegativeIntegerDef =
xmlSchemaInitBasicType("nonNegativeInteger");
xmlSchemaTypeNmtoken = xmlSchemaInitBasicType("NMTOKEN");
xmlSchemaTypesInitialized = 1;
}
/**
* xmlSchemaCleanupTypes:
*
* Cleanup the default XML Schemas type library
*/
void
xmlSchemaCleanupTypes(void) {
if (xmlSchemaTypesInitialized == 0)
return;
xmlHashFree(xmlSchemaTypesBank, (xmlHashDeallocator) xmlSchemaFreeType);
xmlSchemaTypesInitialized = 0;
}
/**
* xmlSchemaNewValue:
* @type: the value type
*
* Allocate a new simple type value
*
* Returns a pointer to the new value or NULL in case of error
*/
static xmlSchemaValPtr
xmlSchemaNewValue(xmlSchemaValType type) {
xmlSchemaValPtr value;
value = (xmlSchemaValPtr) xmlMalloc(sizeof(xmlSchemaVal));
if (value == NULL) {
return(NULL);
}
memset(value, 0, sizeof(xmlSchemaVal));
value->type = type;
return(value);
}
/**
* xmlSchemaFreeValue:
* @value: the value to free
*
* Cleanup the default XML Schemas type library
*/
void
xmlSchemaFreeValue(xmlSchemaValPtr value) {
if (value == NULL)
return;
xmlFree(value);
}
/**
* xmlSchemaGetPredefinedType:
* @name: the type name
* @ns: the URI of the namespace usually "http://www.w3.org/2001/XMLSchema"
*
* Lookup a type in the default XML Schemas type library
*
* Returns the type if found, NULL otherwise
*/
xmlSchemaTypePtr
xmlSchemaGetPredefinedType(const xmlChar *name, const xmlChar *ns) {
if (xmlSchemaTypesInitialized == 0)
xmlSchemaInitTypes();
if (name == NULL)
return(NULL);
return((xmlSchemaTypePtr) xmlHashLookup2(xmlSchemaTypesBank, name, ns));
}
/**
* xmlSchemaValidatePredefinedType:
* @type: the predefined type
* @value: the value to check
* @val: the return computed value
*
* Check that a value conforms to the lexical space of the predefined type.
* if true a value is computed and returned in @val.
*
* Returns 0 if this validates, a positive error code number otherwise
* and -1 in case of internal or API error.
*/
int
xmlSchemaValidatePredefinedType(xmlSchemaTypePtr type, const xmlChar *value,
xmlSchemaValPtr *val) {
xmlSchemaValPtr v;
if (xmlSchemaTypesInitialized == 0)
return(-1);
if (type == NULL)
return(-1);
if (val != NULL)
*val = NULL;
if (type == xmlSchemaTypeStringDef) {
return(0);
} else if (type == xmlSchemaTypeAnyTypeDef) {
return(0);
} else if (type == xmlSchemaTypeAnySimpleTypeDef) {
return(0);
} else if (type == xmlSchemaTypeNmtoken) {
if (xmlValidateNmtokenValue(value))
return(0);
return(1);
} else if (type == xmlSchemaTypeDecimalDef) {
const xmlChar *cur = value, *tmp;
int frac = 0, main, neg = 0;
unsigned long base = 0;
if (cur == NULL)
return(1);
if (*cur == '+')
cur++;
else if (*cur == '-') {
neg = 1;
cur++;
}
tmp = cur;
while ((*cur >= '0') && (*cur <= '9')) {
base = base * 10 + (*cur - '0');
cur++;
}
main = cur - tmp;
if (*cur == '.') {
cur++;
tmp = cur;
while ((*cur >= '0') && (*cur <= '9')) {
base = base * 10 + (*cur - '0');
cur++;
}
frac = cur - tmp;
}
if (*cur != 0)
return(1);
if (val != NULL) {
v = xmlSchemaNewValue(XML_SCHEMAS_DECIMAL);
if (v != NULL) {
v->value.decimal.base = base;
v->value.decimal.sign = neg;
v->value.decimal.frac = frac;
v->value.decimal.total = frac + main;
*val = v;
}
}
return(0);
} else if (type == xmlSchemaTypeDateDef) {
const xmlChar *cur = value;
if (cur == NULL)
return(1);
if (*cur == '-')
cur++;
if ((*cur < '0') || (*cur > '9'))
return(1);
if ((*cur < '0') || (*cur > '9'))
return(1);
if ((*cur < '0') || (*cur > '9'))
return(1);
if ((*cur < '0') || (*cur > '9'))
return(1);
while ((*cur >= '0') && (*cur <= '9'))
cur++;
if (*cur != '-')
return(1);
cur++;
if ((*cur != '0') && (*cur != '1'))
return(1);
if ((*cur == '0') && (cur[1] == '0'))
return(1);
if ((*cur == '1') && ((cur[1] < '0') || (cur[1] > '2')))
return(1);
cur += 2;
if (*cur != '-')
return(1);
cur++;
if ((*cur < '0') || (*cur > '3'))
return(1);
if ((*cur == '0') && (cur[1] == '0'))
return(1);
if ((*cur == '3') && ((cur[1] < '0') || (cur[1] > '1')))
return(1);
cur += 2;
if (*cur != 0)
return(1);
return(0);
} else if (type == xmlSchemaTypePositiveIntegerDef) {
const xmlChar *cur = value;
unsigned long base = 0;
int total = 0;
if (cur == NULL)
return(1);
if (*cur == '+')
cur++;
while ((*cur >= '0') && (*cur <= '9')) {
base = base * 10 + (*cur - '0');
total++;
cur++;
}
if (*cur != 0)
return(1);
if (val != NULL) {
v = xmlSchemaNewValue(XML_SCHEMAS_DECIMAL);
if (v != NULL) {
v->value.decimal.base = base;
v->value.decimal.sign = 0;
v->value.decimal.frac = 0;
v->value.decimal.total = total;
*val = v;
}
}
return(0);
} else if (type == xmlSchemaTypeNonNegativeIntegerDef) {
const xmlChar *cur = value;
unsigned long base = 0;
int total = 0;
int sign = 0;
if (cur == NULL)
return(1);
if (*cur == '-') {
sign = 1;
cur++;
} else if (*cur == '+')
cur++;
while ((*cur >= '0') && (*cur <= '9')) {
base = base * 10 + (*cur - '0');
total++;
cur++;
}
if (*cur != 0)
return(1);
if ((sign == 1) && (base != 0))
return(1);
if (val != NULL) {
v = xmlSchemaNewValue(XML_SCHEMAS_DECIMAL);
if (v != NULL) {
v->value.decimal.base = base;
v->value.decimal.sign = 0;
v->value.decimal.frac = 0;
v->value.decimal.total = total;
*val = v;
}
}
return(0);
} else {
TODO
return(0);
}
}
/**
* xmlSchemaCompareDecimals:
* @x: a first decimal value
* @y: a second decimal value
*
* Compare 2 decimals
*
* Returns -1 if x < y, 0 if x == y, 1 if x > y and -2 in case of error
*/
static int
xmlSchemaCompareDecimals(xmlSchemaValPtr x, xmlSchemaValPtr y)
{
xmlSchemaValPtr swp;
int order = 1;
unsigned long tmp;
if ((x->value.decimal.sign) && (x->value.decimal.sign))
order = -1;
else if (x->value.decimal.sign)
return (-1);
else if (y->value.decimal.sign)
return (1);
if (x->value.decimal.frac == y->value.decimal.frac) {
if (x->value.decimal.base < y->value.decimal.base)
return (-1);
return (x->value.decimal.base > y->value.decimal.base);
}
if (y->value.decimal.frac > x->value.decimal.frac) {
swp = y;
y = x;
x = swp;
order = -order;
}
tmp =
x->value.decimal.base / powten[x->value.decimal.frac -
y->value.decimal.frac];
if (tmp > y->value.decimal.base)
return (order);
if (tmp < y->value.decimal.base)
return (-order);
tmp =
y->value.decimal.base * powten[x->value.decimal.frac -
y->value.decimal.frac];
if (x->value.decimal.base < tmp)
return (-order);
if (x->value.decimal.base == tmp)
return (0);
return (order);
}
/**
* xmlSchemaCompareValues:
* @x: a first value
* @y: a second value
*
* Compare 2 values
*
* Returns -1 if x < y, 0 if x == y, 1 if x > y and -2 in case of error
*/
int
xmlSchemaCompareValues(xmlSchemaValPtr x, xmlSchemaValPtr y) {
if ((x == NULL) || (y == NULL))
return(-2);
switch (x->type) {
case XML_SCHEMAS_STRING:
TODO
case XML_SCHEMAS_DECIMAL:
if (y->type == XML_SCHEMAS_DECIMAL)
return(xmlSchemaCompareDecimals(x, y));
else
return(-2);
default:
TODO
}
}
/**
* xmlSchemaValidateFacet:
* @type: the type declaration
* @facet: the facet to check
* @value: the lexical repr of the value to validate
* @val: the precomputed value
*
* Check a value against a facet condition
*
* Returns 0 if the element is schemas valid, a positive error code
* number otherwise and -1 in case of internal or API error.
*/
int
xmlSchemaValidateFacet(xmlSchemaTypePtr base, xmlSchemaFacetPtr facet,
const xmlChar *value, xmlSchemaValPtr val)
{
int ret;
switch (facet->type) {
case XML_SCHEMA_FACET_PATTERN:
ret = xmlRegexpExec(facet->regexp, value);
if (ret == 1)
return(0);
if (ret == 0) {
TODO /* error code */
return(1);
}
return(ret);
case XML_SCHEMA_FACET_MAXEXCLUSIVE:
ret = xmlSchemaCompareValues(val, facet->val);
if (ret == -2) {
TODO /* error code */
return(-1);
}
if (ret == -1)
return(0);
TODO /* error code */
return(1);
default:
TODO
}
return(0);
}
#endif /* LIBXML_SCHEMAS_ENABLED */

4290
xmlunicode.c Normal file

File diff suppressed because it is too large Load Diff