Initial import
git-svn-id: http://moon:8086/svn/software/trunk/libsrc/xerces-c-3.0.0@1 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
Executable
+166
@@ -0,0 +1,166 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
#
|
||||
# $Id: Makefile.am 631983 2008-02-28 14:30:15Z borisk $
|
||||
#
|
||||
|
||||
bin_PROGRAMS = ${sampleprogs}
|
||||
|
||||
LDADD = ${top_builddir}/src/libxerces-c.la
|
||||
# the -I${top_builddir}/src is needed to pick the xercesc/util/Xerces_autoconf_config.hpp
|
||||
# header file when doing out-of-tree builds
|
||||
AM_CPPFLAGS = -I${top_builddir}/src -I${top_srcdir}/src
|
||||
|
||||
EXTRA_DIST = data/personal.dtd \
|
||||
data/personal.xml \
|
||||
data/personal.xsd \
|
||||
data/personal-schema.xml \
|
||||
data/redirect.dtd
|
||||
|
||||
sampleprogs =
|
||||
|
||||
sampleprogs += CreateDOMDocument
|
||||
CreateDOMDocument_SOURCES = src/CreateDOMDocument/CreateDOMDocument.cpp
|
||||
|
||||
sampleprogs += DOMCount
|
||||
DOMCount_SOURCES = src/DOMCount/DOMCount.cpp \
|
||||
src/DOMCount/DOMCount.hpp
|
||||
|
||||
sampleprogs += DOMPrint
|
||||
DOMPrint_SOURCES = src/DOMPrint/DOMPrint.cpp \
|
||||
src/DOMPrint/DOMPrintErrorHandler.cpp \
|
||||
src/DOMPrint/DOMPrintErrorHandler.hpp \
|
||||
src/DOMPrint/DOMPrintFilter.cpp \
|
||||
src/DOMPrint/DOMPrintFilter.hpp \
|
||||
src/DOMPrint/DOMTreeErrorReporter.cpp \
|
||||
src/DOMPrint/DOMTreeErrorReporter.hpp
|
||||
|
||||
sampleprogs += EnumVal
|
||||
EnumVal_SOURCES = src/EnumVal/EnumVal.cpp
|
||||
|
||||
sampleprogs += MemParse
|
||||
MemParse_SOURCES = src/MemParse/MemParse.cpp \
|
||||
src/MemParse/MemParse.hpp \
|
||||
src/MemParse/MemParseHandlers.cpp \
|
||||
src/MemParse/MemParseHandlers.hpp
|
||||
|
||||
sampleprogs += PParse
|
||||
PParse_SOURCES = src/PParse/PParse.cpp \
|
||||
src/PParse/PParse.hpp \
|
||||
src/PParse/PParseHandlers.cpp \
|
||||
src/PParse/PParseHandlers.hpp
|
||||
|
||||
sampleprogs += PSVIWriter
|
||||
PSVIWriter_SOURCES = src/PSVIWriter/PSVIWriter.cpp \
|
||||
src/PSVIWriter/PSVIWriter.hpp \
|
||||
src/PSVIWriter/PSVIWriterHandlers.cpp \
|
||||
src/PSVIWriter/PSVIWriterHandlers.hpp
|
||||
|
||||
sampleprogs += Redirect
|
||||
Redirect_SOURCES = src/Redirect/Redirect.cpp \
|
||||
src/Redirect/Redirect.hpp \
|
||||
src/Redirect/RedirectHandlers.cpp \
|
||||
src/Redirect/RedirectHandlers.hpp
|
||||
|
||||
sampleprogs += SAX2Count
|
||||
SAX2Count_SOURCES = src/SAX2Count/SAX2Count.cpp \
|
||||
src/SAX2Count/SAX2Count.hpp \
|
||||
src/SAX2Count/SAX2CountHandlers.cpp \
|
||||
src/SAX2Count/SAX2CountHandlers.hpp
|
||||
|
||||
sampleprogs += SAX2Print
|
||||
SAX2Print_SOURCES = src/SAX2Print/SAX2FilterHandlers.cpp \
|
||||
src/SAX2Print/SAX2FilterHandlers.hpp \
|
||||
src/SAX2Print/SAX2Print.cpp \
|
||||
src/SAX2Print/SAX2Print.hpp \
|
||||
src/SAX2Print/SAX2PrintHandlers.cpp \
|
||||
src/SAX2Print/SAX2PrintHandlers.hpp
|
||||
|
||||
sampleprogs += SAXCount
|
||||
SAXCount_SOURCES = src/SAXCount/SAXCount.cpp \
|
||||
src/SAXCount/SAXCount.hpp \
|
||||
src/SAXCount/SAXCountHandlers.cpp \
|
||||
src/SAXCount/SAXCountHandlers.hpp
|
||||
|
||||
sampleprogs += SAXPrint
|
||||
SAXPrint_SOURCES = src/SAXPrint/SAXPrint.cpp \
|
||||
src/SAXPrint/SAXPrint.hpp \
|
||||
src/SAXPrint/SAXPrintHandlers.cpp \
|
||||
src/SAXPrint/SAXPrintHandlers.hpp
|
||||
|
||||
sampleprogs += SCMPrint
|
||||
SCMPrint_SOURCES = src/SCMPrint/SCMPrint.cpp
|
||||
|
||||
sampleprogs += SEnumVal
|
||||
SEnumVal_SOURCES = src/SEnumVal/SEnumVal.cpp
|
||||
|
||||
sampleprogs += StdInParse
|
||||
StdInParse_SOURCES = src/StdInParse/StdInParse.cpp \
|
||||
src/StdInParse/StdInParse.hpp \
|
||||
src/StdInParse/StdInParseHandlers.cpp \
|
||||
src/StdInParse/StdInParseHandlers.hpp
|
||||
|
||||
sampleprogs += XInclude
|
||||
XInclude_SOURCES = src/XInclude/XInclude.cpp \
|
||||
src/XInclude/XInclude.hpp
|
||||
|
||||
#
|
||||
# Override generated rules to provide prettier make rules
|
||||
#
|
||||
# Warning: If Automake changes sufficiently, these rules may need to
|
||||
# be regenerated from the (new) default output of Automake
|
||||
#
|
||||
if XERCES_PRETTY_MAKE
|
||||
.cpp.o:
|
||||
@am__fastdepCXX_TRUE@ @depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`; \
|
||||
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$$depbase.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$$depbase.Tpo" "$$depbase.Po"; else rm -f "$$depbase.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ @source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $<
|
||||
|
||||
.cpp.obj:
|
||||
@am__fastdepCXX_TRUE@ @depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`; \
|
||||
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$$depbase.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$$depbase.Tpo" "$$depbase.Po"; else rm -f "$$depbase.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ @source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
|
||||
.cpp.lo:
|
||||
@am__fastdepCXX_TRUE@ @depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`; \
|
||||
@am__fastdepCXX_TRUE@ if $(LTCXXCOMPILE) -MT $@ -MD -MP -MF "$$depbase.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$$depbase.Tpo" "$$depbase.Plo"; else rm -f "$$depbase.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ @source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $<
|
||||
|
||||
PRETTY_MAKE=${top_srcdir}/config/pretty-make
|
||||
PRETTY_COMPILE=${PRETTY_MAKE} Compiling
|
||||
endif
|
||||
|
||||
CXXCOMPILE = ${PRETTY_COMPILE} \
|
||||
$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
|
||||
LTCXXCOMPILE = ${PRETTY_COMPILE} \
|
||||
$(LIBTOOL) --quiet --tag=CXX --mode=compile \
|
||||
$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
|
||||
|
||||
|
||||
|
||||
Executable
+1022
File diff suppressed because it is too large
Load Diff
Executable
+1
File diff suppressed because one or more lines are too long
Executable
+42
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?proc-inst-1 'foo' ?>
|
||||
<personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation='personal.xsd'>
|
||||
|
||||
<person id="Big.Boss">
|
||||
<name xml:base="foo/bar"><family xml:base="bar/bar">Boss</family> <given xml:base="car/bar">Big</given><?proc-inst-2 'foobar' ?></name>
|
||||
<email>chief@foo.com</email>
|
||||
<link subordinates="one.worker two.worker three.worker four.worker five.worker"/>
|
||||
</person>
|
||||
|
||||
<person id="one.worker" xml:base="/auto/bar">
|
||||
<name xml:base="/car/foo/"><family xml:base="bar/bar">Worker</family> <given>One</given></name>
|
||||
<email>one@foo.com</email>
|
||||
<link manager="Big.Boss"/>
|
||||
</person>
|
||||
|
||||
<person id="two.worker" xml:base="http://www.example.com/car/car">
|
||||
<name xml:base="/bar/foo/"><family xml:base="foo/bar">Worker</family> <given>Two</given></name>
|
||||
<email>two@foo.com</email>
|
||||
<link manager="Big.Boss"/>
|
||||
</person>
|
||||
|
||||
<person id="three.worker">
|
||||
<name><family>Worker</family> <given>Three</given></name>
|
||||
<email>three@foo.com</email>
|
||||
<link manager="Big.Boss"/>
|
||||
</person>
|
||||
|
||||
<person id="four.worker">
|
||||
<name><family>Worker</family> <given>Four</given></name>
|
||||
<email>four@foo.com</email>
|
||||
<link manager="Big.Boss"/>
|
||||
</person>
|
||||
|
||||
<person id="five.worker">
|
||||
<name><family>Worker</family> <given>Five</given></name>
|
||||
<email>five@foo.com</email>
|
||||
<link manager="Big.Boss"/>
|
||||
</person>
|
||||
|
||||
</personnel>
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
<?xml encoding="ISO-8859-1"?>
|
||||
|
||||
<!-- @version: -->
|
||||
|
||||
<!ELEMENT personnel (person)+>
|
||||
<!ELEMENT person (name,email*,url*,link?)>
|
||||
<!ATTLIST person id ID #REQUIRED>
|
||||
<!ELEMENT family (#PCDATA)>
|
||||
<!ELEMENT given (#PCDATA)>
|
||||
<!ELEMENT name (#PCDATA|family|given)*>
|
||||
<!ELEMENT email (#PCDATA)>
|
||||
<!ELEMENT url EMPTY>
|
||||
<!ATTLIST url href CDATA #REQUIRED>
|
||||
<!ELEMENT link EMPTY>
|
||||
<!ATTLIST link
|
||||
manager IDREF #IMPLIED
|
||||
subordinates IDREFS #IMPLIED>
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!DOCTYPE personnel SYSTEM "personal.dtd">
|
||||
|
||||
<!-- @version: -->
|
||||
|
||||
<personnel>
|
||||
|
||||
<person id="Big.Boss" >
|
||||
<name><family>Boss</family> <given>Big</given></name>
|
||||
<email>chief@foo.com</email>
|
||||
<link subordinates="one.worker two.worker three.worker four.worker five.worker"/>
|
||||
</person>
|
||||
|
||||
<person id="one.worker">
|
||||
<name><family>Worker</family> <given>One</given></name>
|
||||
<email>one@foo.com</email>
|
||||
<link manager="Big.Boss"/>
|
||||
</person>
|
||||
|
||||
<person id="two.worker">
|
||||
<name><family>Worker</family> <given>Two</given></name>
|
||||
<email>two@foo.com</email>
|
||||
<link manager="Big.Boss"/>
|
||||
</person>
|
||||
|
||||
<person id="three.worker">
|
||||
<name><family>Worker</family> <given>Three</given></name>
|
||||
<email>three@foo.com</email>
|
||||
<link manager="Big.Boss"/>
|
||||
</person>
|
||||
|
||||
<person id="four.worker">
|
||||
<name><family>Worker</family> <given>Four</given></name>
|
||||
<email>four@foo.com</email>
|
||||
<link manager="Big.Boss"/>
|
||||
</person>
|
||||
|
||||
<person id="five.worker">
|
||||
<name><family>Worker</family> <given>Five</given></name>
|
||||
<email>five@foo.com</email>
|
||||
<link manager="Big.Boss"/>
|
||||
</person>
|
||||
|
||||
</personnel>
|
||||
Executable
+108
@@ -0,0 +1,108 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
|
||||
|
||||
<xs:import namespace="http://www.w3.org/XML/1998/namespace">
|
||||
<xs:annotation>
|
||||
<xs:documentation>
|
||||
The schemaLocation of the relevant file is
|
||||
"http://www.w3.org/2001/xml.xsd"; however,
|
||||
we don't want to assume people are always
|
||||
connected to the 'net when playing with this file.
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:import>
|
||||
|
||||
<xs:element name="personnel">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element ref="person" minOccurs='1' maxOccurs='unbounded'/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:unique name="unique1">
|
||||
<xs:selector xpath="person"/>
|
||||
<xs:field xpath="name/given"/>
|
||||
<xs:field xpath="name/family"/>
|
||||
</xs:unique>
|
||||
<xs:key name='empid'>
|
||||
<xs:selector xpath="person"/>
|
||||
<xs:field xpath="@id"/>
|
||||
</xs:key>
|
||||
<xs:keyref name="keyref1" refer='empid'>
|
||||
<xs:selector xpath="person"/>
|
||||
<xs:field xpath="link/@manager"/>
|
||||
</xs:keyref>
|
||||
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="person">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element ref="name"/>
|
||||
<xs:element ref="email" minOccurs='0' maxOccurs='unbounded'/>
|
||||
<xs:element ref="url" minOccurs='0' maxOccurs='unbounded'/>
|
||||
<xs:element ref="link" minOccurs='0' maxOccurs='1'/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="id" type="xs:ID" use='required'/>
|
||||
<xs:attribute name="note" type="xs:string"/>
|
||||
<xs:attribute name="contr" default="false">
|
||||
<xs:simpleType>
|
||||
<xs:restriction base = "xs:string">
|
||||
<xs:enumeration value="true"/>
|
||||
<xs:enumeration value="false"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="salary" type="xs:integer"/>
|
||||
<xs:anyAttribute namespace="http://www.w3.org/XML/1998/namespace" processContents="skip"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="name">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element ref="family"/>
|
||||
<xs:element ref="given"/>
|
||||
</xs:all>
|
||||
<xs:anyAttribute namespace="http://www.w3.org/XML/1998/namespace" processContents="skip"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="family">
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base='xs:string'>
|
||||
<xs:anyAttribute namespace="http://www.w3.org/XML/1998/namespace" processContents="skip"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="given" >
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base='xs:string'>
|
||||
<xs:anyAttribute namespace="http://www.w3.org/XML/1998/namespace" processContents="skip"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="email" type='xs:string'/>
|
||||
|
||||
<xs:element name="url">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="href" type="xs:string" default="http://"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="link">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="manager" type="xs:IDREF"/>
|
||||
<xs:attribute name="subordinates" type="xs:IDREFS"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:notation name='gif' public='-//APP/Photoshop/4.0' system='photoshop.exe'/>
|
||||
|
||||
</xs:schema>
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
<?xml encoding="ISO-8859-1"?>
|
||||
|
||||
<!-- @version: -->
|
||||
|
||||
<!ELEMENT personnel (person)+>
|
||||
<!ELEMENT person (name,email*,url*,link?)>
|
||||
<!ATTLIST person id ID #REQUIRED>
|
||||
<!ELEMENT family (#PCDATA)>
|
||||
<!ELEMENT given (#PCDATA)>
|
||||
<!ELEMENT name (#PCDATA|family|given)*>
|
||||
<!ELEMENT email (#PCDATA)>
|
||||
<!ELEMENT url EMPTY>
|
||||
<!ATTLIST url href CDATA #REQUIRED>
|
||||
<!ELEMENT link EMPTY>
|
||||
<!ATTLIST link
|
||||
manager IDREF #IMPLIED
|
||||
subordinates IDREFS #IMPLIED>
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: CreateDOMDocument.cpp 676796 2008-07-15 05:04:13Z dbertoni $
|
||||
*/
|
||||
|
||||
/*
|
||||
* This sample illustrates how you can create a DOM tree in memory.
|
||||
* It then prints the count of elements in the tree.
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/dom/DOM.hpp>
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple class that lets us do easy (though not terribly efficient)
|
||||
// trancoding of char* data to XMLCh data.
|
||||
// ---------------------------------------------------------------------------
|
||||
class XStr
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
XStr(const char* const toTranscode)
|
||||
{
|
||||
// Call the private transcoding method
|
||||
fUnicodeForm = XMLString::transcode(toTranscode);
|
||||
}
|
||||
|
||||
~XStr()
|
||||
{
|
||||
XMLString::release(&fUnicodeForm);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
const XMLCh* unicodeForm() const
|
||||
{
|
||||
return fUnicodeForm;
|
||||
}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fUnicodeForm
|
||||
// This is the Unicode XMLCh format of the string.
|
||||
// -----------------------------------------------------------------------
|
||||
XMLCh* fUnicodeForm;
|
||||
};
|
||||
|
||||
#define X(str) XStr(str).unicodeForm()
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// main
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
int main(int argC, char*[])
|
||||
{
|
||||
// Initialize the XML4C2 system.
|
||||
try
|
||||
{
|
||||
XMLPlatformUtils::Initialize();
|
||||
}
|
||||
|
||||
catch(const XMLException& toCatch)
|
||||
{
|
||||
char *pMsg = XMLString::transcode(toCatch.getMessage());
|
||||
XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.\n"
|
||||
<< " Exception message:"
|
||||
<< pMsg;
|
||||
XMLString::release(&pMsg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Watch for special case help request
|
||||
int errorCode = 0;
|
||||
if (argC > 1)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
||||
" CreateDOMDocument\n\n"
|
||||
"This program creates a new DOM document from scratch in memory.\n"
|
||||
"It then prints the count of elements in the tree.\n"
|
||||
<< XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 1;
|
||||
}
|
||||
if(errorCode) {
|
||||
XMLPlatformUtils::Terminate();
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
{
|
||||
// Nest entire test in an inner block.
|
||||
// The tree we create below is the same that the XercesDOMParser would
|
||||
// have created, except that no whitespace text nodes would be created.
|
||||
|
||||
// <company>
|
||||
// <product>Xerces-C</product>
|
||||
// <category idea='great'>XML Parsing Tools</category>
|
||||
// <developedBy>Apache Software Foundation</developedBy>
|
||||
// </company>
|
||||
|
||||
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));
|
||||
|
||||
if (impl != NULL)
|
||||
{
|
||||
try
|
||||
{
|
||||
DOMDocument* doc = impl->createDocument(
|
||||
0, // root element namespace URI.
|
||||
X("company"), // root element name
|
||||
0); // document type object (DTD).
|
||||
|
||||
DOMElement* rootElem = doc->getDocumentElement();
|
||||
|
||||
DOMElement* prodElem = doc->createElement(X("product"));
|
||||
rootElem->appendChild(prodElem);
|
||||
|
||||
DOMText* prodDataVal = doc->createTextNode(X("Xerces-C"));
|
||||
prodElem->appendChild(prodDataVal);
|
||||
|
||||
DOMElement* catElem = doc->createElement(X("category"));
|
||||
rootElem->appendChild(catElem);
|
||||
|
||||
catElem->setAttribute(X("idea"), X("great"));
|
||||
|
||||
DOMText* catDataVal = doc->createTextNode(X("XML Parsing Tools"));
|
||||
catElem->appendChild(catDataVal);
|
||||
|
||||
DOMElement* devByElem = doc->createElement(X("developedBy"));
|
||||
rootElem->appendChild(devByElem);
|
||||
|
||||
DOMText* devByDataVal = doc->createTextNode(X("Apache Software Foundation"));
|
||||
devByElem->appendChild(devByDataVal);
|
||||
|
||||
//
|
||||
// Now count the number of elements in the above DOM tree.
|
||||
//
|
||||
|
||||
const XMLSize_t elementCount = doc->getElementsByTagName(X("*"))->getLength();
|
||||
XERCES_STD_QUALIFIER cout << "The tree just created contains: " << elementCount
|
||||
<< " elements." << XERCES_STD_QUALIFIER endl;
|
||||
|
||||
doc->release();
|
||||
}
|
||||
catch (const OutOfMemoryException&)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 5;
|
||||
}
|
||||
catch (const DOMException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "DOMException code is: " << e.code << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 2;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "An error occurred creating the document" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 3;
|
||||
}
|
||||
} // (inpl != NULL)
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Requested implementation is not supported" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 4;
|
||||
}
|
||||
}
|
||||
|
||||
XMLPlatformUtils::Terminate();
|
||||
return errorCode;
|
||||
}
|
||||
Executable
+464
@@ -0,0 +1,464 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: DOMCount.cpp 676796 2008-07-15 05:04:13Z dbertoni $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/parsers/AbstractDOMParser.hpp>
|
||||
#include <xercesc/dom/DOMImplementation.hpp>
|
||||
#include <xercesc/dom/DOMImplementationLS.hpp>
|
||||
#include <xercesc/dom/DOMImplementationRegistry.hpp>
|
||||
#include <xercesc/dom/DOMLSParser.hpp>
|
||||
#include <xercesc/dom/DOMException.hpp>
|
||||
#include <xercesc/dom/DOMDocument.hpp>
|
||||
#include <xercesc/dom/DOMNodeList.hpp>
|
||||
#include <xercesc/dom/DOMError.hpp>
|
||||
#include <xercesc/dom/DOMLocator.hpp>
|
||||
#include <xercesc/dom/DOMNamedNodeMap.hpp>
|
||||
#include <xercesc/dom/DOMAttr.hpp>
|
||||
#include "DOMCount.hpp"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <fstream>
|
||||
#else
|
||||
#include <fstream.h>
|
||||
#endif
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple program which invokes the DOMParser to build a DOM
|
||||
// tree for the specified input file. It then walks the tree and counts
|
||||
// the number of elements. The element count is then printed.
|
||||
// ---------------------------------------------------------------------------
|
||||
static void usage()
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
||||
" DOMCount [options] <XML file | List file>\n\n"
|
||||
"This program invokes the DOMLSParser, builds the DOM tree,\n"
|
||||
"and then prints the number of elements found in each XML file.\n\n"
|
||||
"Options:\n"
|
||||
" -l Indicate the input file is a List File that has a list of xml files.\n"
|
||||
" Default to off (Input file is an XML file).\n"
|
||||
" -v=xxx Validation scheme [always | never | auto*].\n"
|
||||
" -n Enable namespace processing. Defaults to off.\n"
|
||||
" -s Enable schema processing. Defaults to off.\n"
|
||||
" -f Enable full schema constraint checking. Defaults to off.\n"
|
||||
" -locale=ll_CC specify the locale, default: en_US.\n"
|
||||
" -p Print out names of elements and attributes encountered.\n"
|
||||
" -? Show this help.\n\n"
|
||||
" * = Default if not provided explicitly.\n"
|
||||
<< XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// Recursively Count up the total number of child Elements under the specified Node.
|
||||
// Process attributes of the node, if any.
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
static int countChildElements(DOMNode *n, bool printOutEncounteredEles)
|
||||
{
|
||||
DOMNode *child;
|
||||
int count = 0;
|
||||
if (n) {
|
||||
if (n->getNodeType() == DOMNode::ELEMENT_NODE)
|
||||
{
|
||||
if(printOutEncounteredEles) {
|
||||
char *name = XMLString::transcode(n->getNodeName());
|
||||
XERCES_STD_QUALIFIER cout <<"----------------------------------------------------------"<<XERCES_STD_QUALIFIER endl;
|
||||
XERCES_STD_QUALIFIER cout <<"Encountered Element : "<< name << XERCES_STD_QUALIFIER endl;
|
||||
|
||||
XMLString::release(&name);
|
||||
|
||||
if(n->hasAttributes()) {
|
||||
// get all the attributes of the node
|
||||
DOMNamedNodeMap *pAttributes = n->getAttributes();
|
||||
const XMLSize_t nSize = pAttributes->getLength();
|
||||
XERCES_STD_QUALIFIER cout <<"\tAttributes" << XERCES_STD_QUALIFIER endl;
|
||||
XERCES_STD_QUALIFIER cout <<"\t----------" << XERCES_STD_QUALIFIER endl;
|
||||
for(XMLSize_t i=0;i<nSize;++i) {
|
||||
DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i);
|
||||
// get attribute name
|
||||
char *name = XMLString::transcode(pAttributeNode->getName());
|
||||
|
||||
XERCES_STD_QUALIFIER cout << "\t" << name << "=";
|
||||
XMLString::release(&name);
|
||||
|
||||
// get attribute type
|
||||
name = XMLString::transcode(pAttributeNode->getValue());
|
||||
XERCES_STD_QUALIFIER cout << name << XERCES_STD_QUALIFIER endl;
|
||||
XMLString::release(&name);
|
||||
}
|
||||
}
|
||||
}
|
||||
++count;
|
||||
}
|
||||
for (child = n->getFirstChild(); child != 0; child=child->getNextSibling())
|
||||
count += countChildElements(child, printOutEncounteredEles);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// main
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
int main(int argC, char* argV[])
|
||||
{
|
||||
|
||||
// Check command line and extract arguments.
|
||||
if (argC < 2)
|
||||
{
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* xmlFile = 0;
|
||||
AbstractDOMParser::ValSchemes valScheme = AbstractDOMParser::Val_Auto;
|
||||
bool doNamespaces = false;
|
||||
bool doSchema = false;
|
||||
bool schemaFullChecking = false;
|
||||
bool doList = false;
|
||||
bool errorOccurred = false;
|
||||
bool recognizeNEL = false;
|
||||
bool printOutEncounteredEles = false;
|
||||
char localeStr[64];
|
||||
memset(localeStr, 0, sizeof localeStr);
|
||||
|
||||
int argInd;
|
||||
for (argInd = 1; argInd < argC; argInd++)
|
||||
{
|
||||
// Break out on first parm not starting with a dash
|
||||
if (argV[argInd][0] != '-')
|
||||
break;
|
||||
|
||||
// Watch for special case help request
|
||||
if (!strcmp(argV[argInd], "-?"))
|
||||
{
|
||||
usage();
|
||||
return 2;
|
||||
}
|
||||
else if (!strncmp(argV[argInd], "-v=", 3)
|
||||
|| !strncmp(argV[argInd], "-V=", 3))
|
||||
{
|
||||
const char* const parm = &argV[argInd][3];
|
||||
|
||||
if (!strcmp(parm, "never"))
|
||||
valScheme = AbstractDOMParser::Val_Never;
|
||||
else if (!strcmp(parm, "auto"))
|
||||
valScheme = AbstractDOMParser::Val_Auto;
|
||||
else if (!strcmp(parm, "always"))
|
||||
valScheme = AbstractDOMParser::Val_Always;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -v= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-n")
|
||||
|| !strcmp(argV[argInd], "-N"))
|
||||
{
|
||||
doNamespaces = true;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-s")
|
||||
|| !strcmp(argV[argInd], "-S"))
|
||||
{
|
||||
doSchema = true;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-f")
|
||||
|| !strcmp(argV[argInd], "-F"))
|
||||
{
|
||||
schemaFullChecking = true;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-l")
|
||||
|| !strcmp(argV[argInd], "-L"))
|
||||
{
|
||||
doList = true;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-special:nel"))
|
||||
{
|
||||
// turning this on will lead to non-standard compliance behaviour
|
||||
// it will recognize the unicode character 0x85 as new line character
|
||||
// instead of regular character as specified in XML 1.0
|
||||
// do not turn this on unless really necessary
|
||||
|
||||
recognizeNEL = true;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-p")
|
||||
|| !strcmp(argV[argInd], "-P"))
|
||||
{
|
||||
printOutEncounteredEles = true;
|
||||
}
|
||||
else if (!strncmp(argV[argInd], "-locale=", 8))
|
||||
{
|
||||
// Get out the end of line
|
||||
strcpy(localeStr, &(argV[argInd][8]));
|
||||
}
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[argInd]
|
||||
<< "', ignoring it\n" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// There should be only one and only one parameter left, and that
|
||||
// should be the file name.
|
||||
//
|
||||
if (argInd != argC - 1)
|
||||
{
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Initialize the XML4C system
|
||||
try
|
||||
{
|
||||
if (strlen(localeStr))
|
||||
{
|
||||
XMLPlatformUtils::Initialize(localeStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
XMLPlatformUtils::Initialize();
|
||||
}
|
||||
|
||||
if (recognizeNEL)
|
||||
{
|
||||
XMLPlatformUtils::recognizeNEL(recognizeNEL);
|
||||
}
|
||||
}
|
||||
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Error during initialization! :\n"
|
||||
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Instantiate the DOM parser.
|
||||
static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
|
||||
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(gLS);
|
||||
DOMLSParser *parser = ((DOMImplementationLS*)impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
|
||||
DOMConfiguration *config = parser->getDomConfig();
|
||||
|
||||
config->setParameter(XMLUni::fgDOMNamespaces, doNamespaces);
|
||||
config->setParameter(XMLUni::fgXercesSchema, doSchema);
|
||||
config->setParameter(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
|
||||
|
||||
if (valScheme == AbstractDOMParser::Val_Auto)
|
||||
{
|
||||
config->setParameter(XMLUni::fgDOMValidateIfSchema, true);
|
||||
}
|
||||
else if (valScheme == AbstractDOMParser::Val_Never)
|
||||
{
|
||||
config->setParameter(XMLUni::fgDOMValidate, false);
|
||||
}
|
||||
else if (valScheme == AbstractDOMParser::Val_Always)
|
||||
{
|
||||
config->setParameter(XMLUni::fgDOMValidate, true);
|
||||
}
|
||||
|
||||
// enable datatype normalization - default is off
|
||||
config->setParameter(XMLUni::fgDOMDatatypeNormalization, true);
|
||||
|
||||
// And create our error handler and install it
|
||||
DOMCountErrorHandler errorHandler;
|
||||
config->setParameter(XMLUni::fgDOMErrorHandler, &errorHandler);
|
||||
|
||||
//
|
||||
// Get the starting time and kick off the parse of the indicated
|
||||
// file. Catch any exceptions that might propogate out of it.
|
||||
//
|
||||
unsigned long duration;
|
||||
|
||||
bool more = true;
|
||||
XERCES_STD_QUALIFIER ifstream fin;
|
||||
|
||||
// the input is a list file
|
||||
if (doList)
|
||||
fin.open(argV[argInd]);
|
||||
|
||||
if (fin.fail()) {
|
||||
XERCES_STD_QUALIFIER cerr <<"Cannot open the list file: " << argV[argInd] << XERCES_STD_QUALIFIER endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
while (more)
|
||||
{
|
||||
char fURI[1000];
|
||||
//initialize the array to zeros
|
||||
memset(fURI,0,sizeof(fURI));
|
||||
|
||||
if (doList) {
|
||||
if (! fin.eof() ) {
|
||||
fin.getline (fURI, sizeof(fURI));
|
||||
if (!*fURI)
|
||||
continue;
|
||||
else {
|
||||
xmlFile = fURI;
|
||||
XERCES_STD_QUALIFIER cerr << "==Parsing== " << xmlFile << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
else {
|
||||
xmlFile = argV[argInd];
|
||||
more = false;
|
||||
}
|
||||
|
||||
//reset error count first
|
||||
errorHandler.resetErrors();
|
||||
|
||||
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc = 0;
|
||||
|
||||
try
|
||||
{
|
||||
// reset document pool
|
||||
parser->resetDocumentPool();
|
||||
|
||||
const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
|
||||
doc = parser->parseURI(xmlFile);
|
||||
const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
|
||||
duration = endMillis - startMillis;
|
||||
}
|
||||
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << xmlFile << "'\n"
|
||||
<< "Exception message is: \n"
|
||||
<< StrX(toCatch.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
|
||||
errorOccurred = true;
|
||||
continue;
|
||||
}
|
||||
catch (const DOMException& toCatch)
|
||||
{
|
||||
const unsigned int maxChars = 2047;
|
||||
XMLCh errText[maxChars + 1];
|
||||
|
||||
XERCES_STD_QUALIFIER cerr << "\nDOM Error during parsing: '" << xmlFile << "'\n"
|
||||
<< "DOMException code is: " << toCatch.code << XERCES_STD_QUALIFIER endl;
|
||||
|
||||
if (DOMImplementation::loadDOMExceptionMsg(toCatch.code, errText, maxChars))
|
||||
XERCES_STD_QUALIFIER cerr << "Message is: " << StrX(errText) << XERCES_STD_QUALIFIER endl;
|
||||
|
||||
errorOccurred = true;
|
||||
continue;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nUnexpected exception during parsing: '" << xmlFile << "'\n";
|
||||
errorOccurred = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract the DOM tree, get the list of all the elements and report the
|
||||
// length as the count of elements.
|
||||
//
|
||||
if (errorHandler.getSawErrors())
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nErrors occurred, no output available\n" << XERCES_STD_QUALIFIER endl;
|
||||
errorOccurred = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int elementCount = 0;
|
||||
if (doc) {
|
||||
elementCount = countChildElements((DOMNode*)doc->getDocumentElement(), printOutEncounteredEles);
|
||||
// test getElementsByTagName and getLength
|
||||
XMLCh xa[] = {chAsterisk, chNull};
|
||||
if (elementCount != doc->getElementsByTagName(xa)->getLength()) {
|
||||
XERCES_STD_QUALIFIER cout << "\nErrors occurred, element count is wrong\n" << XERCES_STD_QUALIFIER endl;
|
||||
errorOccurred = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Print out the stats that we collected and time taken.
|
||||
XERCES_STD_QUALIFIER cout << xmlFile << ": " << duration << " ms ("
|
||||
<< elementCount << " elems)." << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Delete the parser itself. Must be done prior to calling Terminate, below.
|
||||
//
|
||||
parser->release();
|
||||
|
||||
// And call the termination method
|
||||
XMLPlatformUtils::Terminate();
|
||||
|
||||
if (doList)
|
||||
fin.close();
|
||||
|
||||
if (errorOccurred)
|
||||
return 4;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
DOMCountErrorHandler::DOMCountErrorHandler() :
|
||||
|
||||
fSawErrors(false)
|
||||
{
|
||||
}
|
||||
|
||||
DOMCountErrorHandler::~DOMCountErrorHandler()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// DOMCountHandlers: Overrides of the DOM ErrorHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
bool DOMCountErrorHandler::handleError(const DOMError& domError)
|
||||
{
|
||||
fSawErrors = true;
|
||||
if (domError.getSeverity() == DOMError::DOM_SEVERITY_WARNING)
|
||||
XERCES_STD_QUALIFIER cerr << "\nWarning at file ";
|
||||
else if (domError.getSeverity() == DOMError::DOM_SEVERITY_ERROR)
|
||||
XERCES_STD_QUALIFIER cerr << "\nError at file ";
|
||||
else
|
||||
XERCES_STD_QUALIFIER cerr << "\nFatal Error at file ";
|
||||
|
||||
XERCES_STD_QUALIFIER cerr << StrX(domError.getLocation()->getURI())
|
||||
<< ", line " << domError.getLocation()->getLineNumber()
|
||||
<< ", char " << domError.getLocation()->getColumnNumber()
|
||||
<< "\n Message: " << StrX(domError.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DOMCountErrorHandler::resetErrors()
|
||||
{
|
||||
fSawErrors = false;
|
||||
}
|
||||
Executable
+130
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: DOMCount.hpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/dom/DOMErrorHandler.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Simple error handler deriviative to install on parser
|
||||
// ---------------------------------------------------------------------------
|
||||
class DOMCountErrorHandler : public DOMErrorHandler
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
DOMCountErrorHandler();
|
||||
~DOMCountErrorHandler();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
bool getSawErrors() const;
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementation of the DOM ErrorHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
bool handleError(const DOMError& domError);
|
||||
void resetErrors();
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
DOMCountErrorHandler(const DOMCountErrorHandler&);
|
||||
void operator=(const DOMCountErrorHandler&);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fSawErrors
|
||||
// This is set if we get any errors, and is queryable via a getter
|
||||
// method. Its used by the main code to suppress output if there are
|
||||
// errors.
|
||||
// -----------------------------------------------------------------------
|
||||
bool fSawErrors;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple class that lets us do easy (though not terribly efficient)
|
||||
// trancoding of XMLCh data to local code page for display.
|
||||
// ---------------------------------------------------------------------------
|
||||
class StrX
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StrX(const XMLCh* const toTranscode)
|
||||
{
|
||||
// Call the private transcoding method
|
||||
fLocalForm = XMLString::transcode(toTranscode);
|
||||
}
|
||||
|
||||
~StrX()
|
||||
{
|
||||
XMLString::release(&fLocalForm);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
const char* localForm() const
|
||||
{
|
||||
return fLocalForm;
|
||||
}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fLocalForm
|
||||
// This is the local code page form of the string.
|
||||
// -----------------------------------------------------------------------
|
||||
char* fLocalForm;
|
||||
};
|
||||
|
||||
inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
||||
{
|
||||
target << toDump.localForm();
|
||||
return target;
|
||||
}
|
||||
|
||||
inline bool DOMCountErrorHandler::getSawErrors() const
|
||||
{
|
||||
return fSawErrors;
|
||||
}
|
||||
Executable
+594
@@ -0,0 +1,594 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: DOMPrint.cpp 669844 2008-06-20 10:11:44Z borisk $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This sample program invokes the XercesDOMParser to build a DOM tree for
|
||||
// the specified input file. It then invokes DOMLSSerializer::write() to
|
||||
// serialize the resultant DOM tree back to XML stream.
|
||||
//
|
||||
// Note:
|
||||
// Application needs to provide its own implementation of
|
||||
// DOMErrorHandler (in this sample, the DOMPrintErrorHandler),
|
||||
// if it would like to receive notification from the serializer
|
||||
// in the case any error occurs during the serialization.
|
||||
//
|
||||
// Application needs to provide its own implementation of
|
||||
// DOMLSSerializerFilter (in this sample, the DOMPrintFilter),
|
||||
// if it would like to filter out certain part of the DOM
|
||||
// representation, but must be aware that thus may render the
|
||||
// resultant XML stream invalid.
|
||||
//
|
||||
// Application may choose any combination of characters as the
|
||||
// end of line sequence to be used in the resultant XML stream,
|
||||
// but must be aware that thus may render the resultant XML
|
||||
// stream ill formed.
|
||||
//
|
||||
// Application may choose a particular encoding name in which
|
||||
// the output XML stream would be, but must be aware that if
|
||||
// characters, unrepresentable in the encoding specified, appearing
|
||||
// in markups, may force the serializer to terminate serialization
|
||||
// prematurely, and thus no complete serialization would be done.
|
||||
//
|
||||
// Application shall query the serializer first, before set any
|
||||
// feature/mode(true, false), or be ready to catch exception if this
|
||||
// feature/mode is not supported by the serializer.
|
||||
//
|
||||
// Application needs to clean up the filter, error handler and
|
||||
// format target objects created for the serialization.
|
||||
//
|
||||
// Limitations:
|
||||
// 1. The encoding="xxx" clause in the XML header should reflect
|
||||
// the system local code page, but does not.
|
||||
// 2. Cases where the XML data contains characters that can not
|
||||
// be represented in the system local code page are not handled.
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
|
||||
#include <xercesc/dom/DOM.hpp>
|
||||
|
||||
#include <xercesc/framework/StdOutFormatTarget.hpp>
|
||||
#include <xercesc/framework/LocalFileFormatTarget.hpp>
|
||||
#include <xercesc/parsers/XercesDOMParser.hpp>
|
||||
#include <xercesc/util/XMLUni.hpp>
|
||||
|
||||
#include "DOMTreeErrorReporter.hpp"
|
||||
#include "DOMPrintFilter.hpp"
|
||||
#include "DOMPrintErrorHandler.hpp"
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local data
|
||||
//
|
||||
// gXmlFile
|
||||
// The path to the file to parser. Set via command line.
|
||||
//
|
||||
// gDoNamespaces
|
||||
// Indicates whether namespace processing should be done.
|
||||
//
|
||||
// gDoSchema
|
||||
// Indicates whether schema processing should be done.
|
||||
//
|
||||
// gSchemaFullChecking
|
||||
// Indicates whether full schema constraint checking should be done.
|
||||
//
|
||||
// gDoCreate
|
||||
// Indicates whether entity reference nodes needs to be created or not
|
||||
// Defaults to false
|
||||
//
|
||||
// gOutputEncoding
|
||||
// The encoding we are to output in. If not set on the command line,
|
||||
// then it is defaults to the encoding of the input XML file.
|
||||
//
|
||||
// gSplitCdataSections
|
||||
// Indicates whether split-cdata-sections is to be enabled or not.
|
||||
//
|
||||
// gDiscardDefaultContent
|
||||
// Indicates whether default content is discarded or not.
|
||||
//
|
||||
// gUseFilter
|
||||
// Indicates if user wants to plug in the DOMPrintFilter.
|
||||
//
|
||||
// gValScheme
|
||||
// Indicates what validation scheme to use. It defaults to 'auto', but
|
||||
// can be set via the -v= command.
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
static char* gXmlFile = 0;
|
||||
static bool gDoNamespaces = false;
|
||||
static bool gDoSchema = false;
|
||||
static bool gSchemaFullChecking = false;
|
||||
static bool gDoCreate = false;
|
||||
|
||||
static char* goutputfile = 0;
|
||||
static char* gXPathExpression = 0;
|
||||
|
||||
// options for DOMLSSerializer's features
|
||||
static XMLCh* gOutputEncoding = 0;
|
||||
|
||||
static bool gSplitCdataSections = true;
|
||||
static bool gDiscardDefaultContent = true;
|
||||
static bool gUseFilter = false;
|
||||
static bool gFormatPrettyPrint = false;
|
||||
static bool gWriteBOM = false;
|
||||
|
||||
static XercesDOMParser::ValSchemes gValScheme = XercesDOMParser::Val_Auto;
|
||||
|
||||
|
||||
// Prototypes for internally used functions
|
||||
void usage();
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// Usage()
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
void usage()
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
||||
" DOMPrint [options] <XML file>\n\n"
|
||||
"This program invokes the DOM parser, and builds the DOM tree.\n"
|
||||
"It then asks the DOMLSSerializer to serialize the DOM tree.\n"
|
||||
"Options:\n"
|
||||
" -e create entity reference nodes. Default is no expansion.\n"
|
||||
" -v=xxx Validation scheme [always | never | auto*].\n"
|
||||
" -n Enable namespace processing. Default is off.\n"
|
||||
" -s Enable schema processing. Default is off.\n"
|
||||
" -f Enable full schema constraint checking. Defaults is off.\n"
|
||||
" -wenc=XXX Use a particular encoding for output. Default is\n"
|
||||
" the same encoding as the input XML file. UTF-8 if\n"
|
||||
" input XML file has not XML declaration.\n"
|
||||
" -wfile=xxx Write to a file instead of stdout.\n"
|
||||
" -wscs=xxx Enable/Disable split-cdata-sections. Default on\n"
|
||||
" -wddc=xxx Enable/Disable discard-default-content. Default on\n"
|
||||
" -wflt=xxx Enable/Disable filtering. Default off\n"
|
||||
" -wfpp=xxx Enable/Disable format-pretty-print. Default off\n"
|
||||
" -wbom=xxx Enable/Disable write Byte-Order-Mark Default off\n"
|
||||
" -xpath=xxx Prints only the nodes matching the given XPath.\n"
|
||||
" -? Show this help.\n\n"
|
||||
" * = Default if not provided explicitly.\n\n"
|
||||
"The parser has intrinsic support for the following encodings:\n"
|
||||
" UTF-8, USASCII, ISO8859-1, UTF-16[BL]E, UCS-4[BL]E,\n"
|
||||
" WINDOWS-1252, IBM1140, IBM037, IBM1047.\n"
|
||||
<< XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// main
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
int main(int argC, char* argV[])
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
// Initialize the XML4C2 system
|
||||
try
|
||||
{
|
||||
XMLPlatformUtils::Initialize();
|
||||
}
|
||||
|
||||
catch(const XMLException &toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.\n"
|
||||
<< " Exception message:"
|
||||
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check command line and extract arguments.
|
||||
if (argC < 2)
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// See if non validating dom parser configuration is requested.
|
||||
int parmInd;
|
||||
for (parmInd = 1; parmInd < argC; parmInd++)
|
||||
{
|
||||
// Break out on first parm not starting with a dash
|
||||
if (argV[parmInd][0] != '-')
|
||||
break;
|
||||
|
||||
// Watch for special case help request
|
||||
if (!strcmp(argV[parmInd], "-?"))
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-v=", 3)
|
||||
|| !strncmp(argV[parmInd], "-V=", 3))
|
||||
{
|
||||
const char* const parm = &argV[parmInd][3];
|
||||
|
||||
if (!strcmp(parm, "never"))
|
||||
gValScheme = XercesDOMParser::Val_Never;
|
||||
else if (!strcmp(parm, "auto"))
|
||||
gValScheme = XercesDOMParser::Val_Auto;
|
||||
else if (!strcmp(parm, "always"))
|
||||
gValScheme = XercesDOMParser::Val_Always;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -v= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-n")
|
||||
|| !strcmp(argV[parmInd], "-N"))
|
||||
{
|
||||
gDoNamespaces = true;
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-s")
|
||||
|| !strcmp(argV[parmInd], "-S"))
|
||||
{
|
||||
gDoSchema = true;
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-f")
|
||||
|| !strcmp(argV[parmInd], "-F"))
|
||||
{
|
||||
gSchemaFullChecking = true;
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-e")
|
||||
|| !strcmp(argV[parmInd], "-E"))
|
||||
{
|
||||
gDoCreate = true;
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-wenc=", 6))
|
||||
{
|
||||
// Get out the encoding name
|
||||
gOutputEncoding = XMLString::transcode( &(argV[parmInd][6]) );
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-wfile=", 7))
|
||||
{
|
||||
goutputfile = &(argV[parmInd][7]);
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-wddc=", 6))
|
||||
{
|
||||
const char* const parm = &argV[parmInd][6];
|
||||
|
||||
if (!strcmp(parm, "on"))
|
||||
gDiscardDefaultContent = true;
|
||||
else if (!strcmp(parm, "off"))
|
||||
gDiscardDefaultContent = false;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -wddc= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-wscs=", 6))
|
||||
{
|
||||
const char* const parm = &argV[parmInd][6];
|
||||
|
||||
if (!strcmp(parm, "on"))
|
||||
gSplitCdataSections = true;
|
||||
else if (!strcmp(parm, "off"))
|
||||
gSplitCdataSections = false;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -wscs= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-wflt=", 6))
|
||||
{
|
||||
const char* const parm = &argV[parmInd][6];
|
||||
|
||||
if (!strcmp(parm, "on"))
|
||||
gUseFilter = true;
|
||||
else if (!strcmp(parm, "off"))
|
||||
gUseFilter = false;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -wflt= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-wfpp=", 6))
|
||||
{
|
||||
const char* const parm = &argV[parmInd][6];
|
||||
|
||||
if (!strcmp(parm, "on"))
|
||||
gFormatPrettyPrint = true;
|
||||
else if (!strcmp(parm, "off"))
|
||||
gFormatPrettyPrint = false;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -wfpp= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-wbom=", 6))
|
||||
{
|
||||
const char* const parm = &argV[parmInd][6];
|
||||
|
||||
if (!strcmp(parm, "on"))
|
||||
gWriteBOM = true;
|
||||
else if (!strcmp(parm, "off"))
|
||||
gWriteBOM = false;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -wbom= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-xpath=", 7))
|
||||
{
|
||||
gXPathExpression = &(argV[parmInd][7]);
|
||||
}
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[parmInd]
|
||||
<< "', ignoring it.\n" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// And now we have to have only one parameter left and it must be
|
||||
// the file name.
|
||||
//
|
||||
if (parmInd + 1 != argC)
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 1;
|
||||
}
|
||||
gXmlFile = argV[parmInd];
|
||||
|
||||
//
|
||||
// Create our parser, then attach an error handler to the parser.
|
||||
// The parser will call back to methods of the ErrorHandler if it
|
||||
// discovers errors during the course of parsing the XML document.
|
||||
//
|
||||
XercesDOMParser *parser = new XercesDOMParser;
|
||||
parser->setValidationScheme(gValScheme);
|
||||
parser->setDoNamespaces(gDoNamespaces);
|
||||
parser->setDoSchema(gDoSchema);
|
||||
parser->setValidationSchemaFullChecking(gSchemaFullChecking);
|
||||
parser->setCreateEntityReferenceNodes(gDoCreate);
|
||||
|
||||
DOMTreeErrorReporter *errReporter = new DOMTreeErrorReporter();
|
||||
parser->setErrorHandler(errReporter);
|
||||
|
||||
//
|
||||
// Parse the XML file, catching any XML exceptions that might propogate
|
||||
// out of it.
|
||||
//
|
||||
bool errorsOccured = false;
|
||||
try
|
||||
{
|
||||
parser->parse(gXmlFile);
|
||||
}
|
||||
catch (const OutOfMemoryException&)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
|
||||
errorsOccured = true;
|
||||
}
|
||||
catch (const XMLException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "An error occurred during parsing\n Message: "
|
||||
<< StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
errorsOccured = true;
|
||||
}
|
||||
|
||||
catch (const DOMException& e)
|
||||
{
|
||||
const unsigned int maxChars = 2047;
|
||||
XMLCh errText[maxChars + 1];
|
||||
|
||||
XERCES_STD_QUALIFIER cerr << "\nDOM Error during parsing: '" << gXmlFile << "'\n"
|
||||
<< "DOMException code is: " << e.code << XERCES_STD_QUALIFIER endl;
|
||||
|
||||
if (DOMImplementation::loadDOMExceptionMsg(e.code, errText, maxChars))
|
||||
XERCES_STD_QUALIFIER cerr << "Message is: " << StrX(errText) << XERCES_STD_QUALIFIER endl;
|
||||
|
||||
errorsOccured = true;
|
||||
}
|
||||
|
||||
catch (...)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "An error occurred during parsing\n " << XERCES_STD_QUALIFIER endl;
|
||||
errorsOccured = true;
|
||||
}
|
||||
|
||||
// If the parse was successful, output the document data from the DOM tree
|
||||
if (!errorsOccured && !errReporter->getSawErrors())
|
||||
{
|
||||
DOMPrintFilter *myFilter = 0;
|
||||
|
||||
try
|
||||
{
|
||||
// get a serializer, an instance of DOMLSSerializer
|
||||
XMLCh tempStr[3] = {chLatin_L, chLatin_S, chNull};
|
||||
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
|
||||
DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
|
||||
DOMLSOutput *theOutputDesc = ((DOMImplementationLS*)impl)->createLSOutput();
|
||||
|
||||
// set user specified output encoding
|
||||
theOutputDesc->setEncoding(gOutputEncoding);
|
||||
|
||||
// plug in user's own filter
|
||||
if (gUseFilter)
|
||||
{
|
||||
// even we say to show attribute, but the DOMLSSerializer
|
||||
// will not show attribute nodes to the filter as
|
||||
// the specs explicitly says that DOMLSSerializer shall
|
||||
// NOT show attributes to DOMLSSerializerFilter.
|
||||
//
|
||||
// so DOMNodeFilter::SHOW_ATTRIBUTE has no effect.
|
||||
// same DOMNodeFilter::SHOW_DOCUMENT_TYPE, no effect.
|
||||
//
|
||||
myFilter = new DOMPrintFilter(DOMNodeFilter::SHOW_ELEMENT |
|
||||
DOMNodeFilter::SHOW_ATTRIBUTE |
|
||||
DOMNodeFilter::SHOW_DOCUMENT_TYPE);
|
||||
theSerializer->setFilter(myFilter);
|
||||
}
|
||||
|
||||
// plug in user's own error handler
|
||||
DOMErrorHandler *myErrorHandler = new DOMPrintErrorHandler();
|
||||
DOMConfiguration* serializerConfig=theSerializer->getDomConfig();
|
||||
serializerConfig->setParameter(XMLUni::fgDOMErrorHandler, myErrorHandler);
|
||||
|
||||
// set feature if the serializer supports the feature/mode
|
||||
if (serializerConfig->canSetParameter(XMLUni::fgDOMWRTSplitCdataSections, gSplitCdataSections))
|
||||
serializerConfig->setParameter(XMLUni::fgDOMWRTSplitCdataSections, gSplitCdataSections);
|
||||
|
||||
if (serializerConfig->canSetParameter(XMLUni::fgDOMWRTDiscardDefaultContent, gDiscardDefaultContent))
|
||||
serializerConfig->setParameter(XMLUni::fgDOMWRTDiscardDefaultContent, gDiscardDefaultContent);
|
||||
|
||||
if (serializerConfig->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, gFormatPrettyPrint))
|
||||
serializerConfig->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, gFormatPrettyPrint);
|
||||
|
||||
if (serializerConfig->canSetParameter(XMLUni::fgDOMWRTBOM, gWriteBOM))
|
||||
serializerConfig->setParameter(XMLUni::fgDOMWRTBOM, gWriteBOM);
|
||||
|
||||
//
|
||||
// Plug in a format target to receive the resultant
|
||||
// XML stream from the serializer.
|
||||
//
|
||||
// StdOutFormatTarget prints the resultant XML stream
|
||||
// to stdout once it receives any thing from the serializer.
|
||||
//
|
||||
XMLFormatTarget *myFormTarget;
|
||||
if (goutputfile)
|
||||
myFormTarget=new LocalFileFormatTarget(goutputfile);
|
||||
else
|
||||
myFormTarget=new StdOutFormatTarget();
|
||||
theOutputDesc->setByteStream(myFormTarget);
|
||||
|
||||
// get the DOM representation
|
||||
DOMDocument *doc = parser->getDocument();
|
||||
|
||||
//
|
||||
// do the serialization through DOMLSSerializer::write();
|
||||
//
|
||||
if(gXPathExpression!=NULL)
|
||||
{
|
||||
XMLCh* xpathStr=XMLString::transcode(gXPathExpression);
|
||||
DOMElement* root = doc->getDocumentElement();
|
||||
try
|
||||
{
|
||||
DOMXPathNSResolver* resolver=doc->createNSResolver(root);
|
||||
DOMXPathResult* result=doc->evaluate(
|
||||
xpathStr,
|
||||
root,
|
||||
resolver,
|
||||
DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
|
||||
NULL);
|
||||
|
||||
XMLSize_t nLength = result->getSnapshotLength();
|
||||
for(XMLSize_t i = 0; i < nLength; i++)
|
||||
{
|
||||
result->snapshotItem(i);
|
||||
theSerializer->write(result->getNodeValue(), theOutputDesc);
|
||||
}
|
||||
|
||||
result->release();
|
||||
resolver->release ();
|
||||
}
|
||||
catch(const DOMXPathException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "An error occurred during processing of the XPath expression. Msg is:"
|
||||
<< XERCES_STD_QUALIFIER endl
|
||||
<< StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
retval = 4;
|
||||
}
|
||||
catch(const DOMException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "An error occurred during processing of the XPath expression. Msg is:"
|
||||
<< XERCES_STD_QUALIFIER endl
|
||||
<< StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
retval = 4;
|
||||
}
|
||||
XMLString::release(&xpathStr);
|
||||
}
|
||||
else
|
||||
theSerializer->write(doc, theOutputDesc);
|
||||
|
||||
theOutputDesc->release();
|
||||
theSerializer->release();
|
||||
|
||||
//
|
||||
// Filter, formatTarget and error handler
|
||||
// are NOT owned by the serializer.
|
||||
//
|
||||
delete myFormTarget;
|
||||
delete myErrorHandler;
|
||||
|
||||
if (gUseFilter)
|
||||
delete myFilter;
|
||||
|
||||
}
|
||||
catch (const OutOfMemoryException&)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
|
||||
retval = 5;
|
||||
}
|
||||
catch (XMLException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "An error occurred during creation of output transcoder. Msg is:"
|
||||
<< XERCES_STD_QUALIFIER endl
|
||||
<< StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
retval = 4;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
retval = 4;
|
||||
|
||||
//
|
||||
// Clean up the error handler. The parser does not adopt handlers
|
||||
// since they could be many objects or one object installed for multiple
|
||||
// handlers.
|
||||
//
|
||||
delete errReporter;
|
||||
|
||||
//
|
||||
// Delete the parser itself. Must be done prior to calling Terminate, below.
|
||||
//
|
||||
delete parser;
|
||||
|
||||
XMLString::release(&gOutputEncoding);
|
||||
|
||||
// And call the termination method
|
||||
XMLPlatformUtils::Terminate();
|
||||
|
||||
return retval;
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: DOMPrintErrorHandler.cpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/dom/DOMError.hpp>
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
|
||||
#include "DOMPrintErrorHandler.hpp"
|
||||
|
||||
bool DOMPrintErrorHandler::handleError(const DOMError &domError)
|
||||
{
|
||||
// Display whatever error message passed from the serializer
|
||||
if (domError.getSeverity() == DOMError::DOM_SEVERITY_WARNING)
|
||||
XERCES_STD_QUALIFIER cerr << "\nWarning Message: ";
|
||||
else if (domError.getSeverity() == DOMError::DOM_SEVERITY_ERROR)
|
||||
XERCES_STD_QUALIFIER cerr << "\nError Message: ";
|
||||
else
|
||||
XERCES_STD_QUALIFIER cerr << "\nFatal Message: ";
|
||||
|
||||
char *msg = XMLString::transcode(domError.getMessage());
|
||||
XERCES_STD_QUALIFIER cerr<< msg <<XERCES_STD_QUALIFIER endl;
|
||||
XMLString::release(&msg);
|
||||
|
||||
// Instructs the serializer to continue serialization if possible.
|
||||
return true;
|
||||
}
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: DOMPrintErrorHandler.hpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DOM_PRINT_ERROR_HANDLER_HPP
|
||||
#define DOM_PRINT_ERROR_HANDLER_HPP
|
||||
|
||||
#include <xercesc/dom/DOMErrorHandler.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
class DOMPrintErrorHandler : public DOMErrorHandler
|
||||
{
|
||||
public:
|
||||
|
||||
DOMPrintErrorHandler(){};
|
||||
~DOMPrintErrorHandler(){};
|
||||
|
||||
/** @name The error handler interface */
|
||||
bool handleError(const DOMError& domError);
|
||||
void resetErrors(){};
|
||||
|
||||
private :
|
||||
/* Unimplemented constructors and operators */
|
||||
DOMPrintErrorHandler(const DOMErrorHandler&);
|
||||
void operator=(const DOMErrorHandler&);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Executable
+111
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: DOMPrintFilter.cpp 671894 2008-06-26 13:29:21Z borisk $
|
||||
*/
|
||||
|
||||
#include "DOMPrintFilter.hpp"
|
||||
#include <xercesc/util/XMLUniDefs.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
|
||||
static const XMLCh element_person[]=
|
||||
{
|
||||
chLatin_p, chLatin_e, chLatin_r, chLatin_s, chLatin_o, chLatin_n, chNull
|
||||
};
|
||||
|
||||
static const XMLCh element_link[]=
|
||||
{
|
||||
chLatin_l, chLatin_i, chLatin_n, chLatin_k, chNull
|
||||
};
|
||||
|
||||
DOMPrintFilter::DOMPrintFilter(ShowType whatToShow)
|
||||
:fWhatToShow(whatToShow)
|
||||
{}
|
||||
|
||||
DOMNodeFilter::FilterAction DOMPrintFilter::
|
||||
acceptNode(const DOMNode* node) const
|
||||
{
|
||||
//
|
||||
// The DOMLSSerializer shall call getWhatToShow() before calling
|
||||
// acceptNode(), to show nodes which are supposed to be
|
||||
// shown to this filter.
|
||||
//
|
||||
// REVISIT: In case the DOMLSSerializer does not follow the protocol,
|
||||
// Shall the filter honour, or NOT, what it claims
|
||||
// it is interested in ?
|
||||
//
|
||||
// The DOMLS specs does not specify that acceptNode() shall do
|
||||
// this way, or not, so it is up the implementation,
|
||||
// to skip the code below for the sake of performance ...
|
||||
//
|
||||
if ((getWhatToShow() & (1 << (node->getNodeType() - 1))) == 0)
|
||||
return DOMNodeFilter::FILTER_ACCEPT;
|
||||
|
||||
switch (node->getNodeType())
|
||||
{
|
||||
case DOMNode::ELEMENT_NODE:
|
||||
{
|
||||
// for element whose name is "person", skip it
|
||||
if (XMLString::compareString(node->getNodeName(), element_person)==0)
|
||||
return DOMNodeFilter::FILTER_SKIP;
|
||||
// for element whose name is "line", reject it
|
||||
if (XMLString::compareString(node->getNodeName(), element_link)==0)
|
||||
return DOMNodeFilter::FILTER_REJECT;
|
||||
// for rest, accept it
|
||||
return DOMNodeFilter::FILTER_ACCEPT;
|
||||
|
||||
break;
|
||||
}
|
||||
case DOMNode::COMMENT_NODE:
|
||||
{
|
||||
// the WhatToShow will make this no effect
|
||||
return DOMNodeFilter::FILTER_REJECT;
|
||||
break;
|
||||
}
|
||||
case DOMNode::TEXT_NODE:
|
||||
{
|
||||
// the WhatToShow will make this no effect
|
||||
return DOMNodeFilter::FILTER_REJECT;
|
||||
break;
|
||||
}
|
||||
case DOMNode::DOCUMENT_TYPE_NODE:
|
||||
{
|
||||
// even we say we are going to process document type,
|
||||
// we are not able be to see this node since
|
||||
// DOMLSSerializerImpl (a XercesC's default implementation
|
||||
// of DOMLSSerializer) will not pass DocumentType node to
|
||||
// this filter.
|
||||
//
|
||||
return DOMNodeFilter::FILTER_REJECT; // no effect
|
||||
break;
|
||||
}
|
||||
case DOMNode::DOCUMENT_NODE:
|
||||
{
|
||||
// same as DOCUMENT_NODE
|
||||
return DOMNodeFilter::FILTER_REJECT; // no effect
|
||||
break;
|
||||
}
|
||||
default :
|
||||
{
|
||||
return DOMNodeFilter::FILTER_ACCEPT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return DOMNodeFilter::FILTER_ACCEPT;
|
||||
}
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: DOMPrintFilter.hpp 671894 2008-06-26 13:29:21Z borisk $
|
||||
*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// DOMPrintFilter.hpp: a sample implementation of DOMWriterFilter.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef DOMPrintFilter_HEADER_GUARD_
|
||||
#define DOMPrintFilter_HEADER_GUARD_
|
||||
|
||||
#include <xercesc/dom/DOMLSSerializerFilter.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
class DOMPrintFilter : public DOMLSSerializerFilter {
|
||||
public:
|
||||
|
||||
DOMPrintFilter(ShowType whatToShow = DOMNodeFilter::SHOW_ALL);
|
||||
~DOMPrintFilter(){};
|
||||
|
||||
virtual FilterAction acceptNode(const DOMNode*) const;
|
||||
virtual ShowType getWhatToShow() const {return fWhatToShow;};
|
||||
|
||||
private:
|
||||
// unimplemented copy ctor and assignement operator
|
||||
DOMPrintFilter(const DOMPrintFilter&);
|
||||
DOMPrintFilter & operator = (const DOMPrintFilter&);
|
||||
|
||||
ShowType fWhatToShow;
|
||||
};
|
||||
|
||||
#endif
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: DOMTreeErrorReporter.cpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/sax/SAXParseException.hpp>
|
||||
#include "DOMTreeErrorReporter.hpp"
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
void DOMTreeErrorReporter::warning(const SAXParseException&)
|
||||
{
|
||||
//
|
||||
// Ignore all warnings.
|
||||
//
|
||||
}
|
||||
|
||||
void DOMTreeErrorReporter::error(const SAXParseException& toCatch)
|
||||
{
|
||||
fSawErrors = true;
|
||||
XERCES_STD_QUALIFIER cerr << "Error at file \"" << StrX(toCatch.getSystemId())
|
||||
<< "\", line " << toCatch.getLineNumber()
|
||||
<< ", column " << toCatch.getColumnNumber()
|
||||
<< "\n Message: " << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void DOMTreeErrorReporter::fatalError(const SAXParseException& toCatch)
|
||||
{
|
||||
fSawErrors = true;
|
||||
XERCES_STD_QUALIFIER cerr << "Fatal Error at file \"" << StrX(toCatch.getSystemId())
|
||||
<< "\", line " << toCatch.getLineNumber()
|
||||
<< ", column " << toCatch.getColumnNumber()
|
||||
<< "\n Message: " << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void DOMTreeErrorReporter::resetErrors()
|
||||
{
|
||||
fSawErrors = false;
|
||||
}
|
||||
|
||||
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: DOMTreeErrorReporter.hpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
#include <xercesc/util/XercesDefs.hpp>
|
||||
#include <xercesc/sax/ErrorHandler.hpp>
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
|
||||
class DOMTreeErrorReporter : public ErrorHandler
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
DOMTreeErrorReporter() :
|
||||
fSawErrors(false)
|
||||
{
|
||||
}
|
||||
|
||||
~DOMTreeErrorReporter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementation of the error handler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void warning(const SAXParseException& toCatch);
|
||||
void error(const SAXParseException& toCatch);
|
||||
void fatalError(const SAXParseException& toCatch);
|
||||
void resetErrors();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
bool getSawErrors() const;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fSawErrors
|
||||
// This is set if we get any errors, and is queryable via a getter
|
||||
// method. Its used by the main code to suppress output if there are
|
||||
// errors.
|
||||
// -----------------------------------------------------------------------
|
||||
bool fSawErrors;
|
||||
};
|
||||
|
||||
inline bool DOMTreeErrorReporter::getSawErrors() const
|
||||
{
|
||||
return fSawErrors;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple class that lets us do easy (though not terribly efficient)
|
||||
// trancoding of XMLCh data to local code page for display.
|
||||
// ---------------------------------------------------------------------------
|
||||
class StrX
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StrX(const XMLCh* const toTranscode)
|
||||
{
|
||||
// Call the private transcoding method
|
||||
fLocalForm = XMLString::transcode(toTranscode);
|
||||
}
|
||||
|
||||
~StrX()
|
||||
{
|
||||
XMLString::release(&fLocalForm);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
const char* localForm() const
|
||||
{
|
||||
return fLocalForm;
|
||||
}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fLocalForm
|
||||
// This is the local code page form of the string.
|
||||
// -----------------------------------------------------------------------
|
||||
char* fLocalForm;
|
||||
};
|
||||
|
||||
inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
||||
{
|
||||
target << toDump.localForm();
|
||||
return target;
|
||||
}
|
||||
|
||||
Executable
+284
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: EnumVal.cpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/NameIdPool.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/framework/XMLValidator.hpp>
|
||||
#include <xercesc/parsers/SAXParser.hpp>
|
||||
#include <xercesc/validators/DTD/DTDValidator.hpp>
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Forward references
|
||||
// ---------------------------------------------------------------------------
|
||||
static void usage();
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple class that lets us do easy (though not terribly efficient)
|
||||
// trancoding of XMLCh data to local code page for display.
|
||||
// ---------------------------------------------------------------------------
|
||||
class StrX
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StrX(const XMLCh* const toTranscode)
|
||||
{
|
||||
// Call the private transcoding method
|
||||
fLocalForm = XMLString::transcode(toTranscode);
|
||||
}
|
||||
|
||||
~StrX()
|
||||
{
|
||||
XMLString::release(&fLocalForm);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
const char* localForm() const
|
||||
{
|
||||
return fLocalForm;
|
||||
}
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fLocalForm
|
||||
// This is the local code page form of the string.
|
||||
// -----------------------------------------------------------------------
|
||||
char* fLocalForm;
|
||||
};
|
||||
|
||||
inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
||||
{
|
||||
target << toDump.localForm();
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
static void usage()
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
||||
" EnumVal <XML file>\n\n"
|
||||
"This program parses the specified XML file, then shows how to\n"
|
||||
"enumerate the contents of the DTD Grammar. Essentially,\n"
|
||||
"shows how one can access the DTD information stored in internal\n"
|
||||
"data structures.\n"
|
||||
<< XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Program entry point
|
||||
// ---------------------------------------------------------------------------
|
||||
int main(int argC, char* argV[])
|
||||
{
|
||||
// Initialize the XML4C system
|
||||
try
|
||||
{
|
||||
XMLPlatformUtils::Initialize();
|
||||
}
|
||||
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
|
||||
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check command line and extract arguments.
|
||||
if (argC < 2)
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// We only have one required parameter, which is the file to process
|
||||
if ((argC != 2) || (*(argV[1]) == '-'))
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* xmlFile = argV[1];
|
||||
SAXParser::ValSchemes valScheme = SAXParser::Val_Auto;
|
||||
|
||||
//
|
||||
// Create a DTD validator to be used for our validation work. Then create
|
||||
// a SAX parser object and pass it our validator. Then, according to what
|
||||
// we were told on the command line, set it to validate or not. He owns
|
||||
// the validator, so we have to allocate it.
|
||||
//
|
||||
int errorCount = 0;
|
||||
DTDValidator* valToUse = new DTDValidator;
|
||||
SAXParser* parser = new SAXParser(valToUse);
|
||||
parser->setValidationScheme(valScheme);
|
||||
|
||||
//
|
||||
// Get the starting time and kick off the parse of the indicated
|
||||
// file. Catch any exceptions that might propogate out of it.
|
||||
//
|
||||
int errorCode = 0;
|
||||
try
|
||||
{
|
||||
parser->parse(xmlFile);
|
||||
errorCount = parser->getErrorCount();
|
||||
}
|
||||
catch (const OutOfMemoryException&)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 5;
|
||||
}
|
||||
catch (const XMLException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << xmlFile << "'\n"
|
||||
<< "Exception message is: \n"
|
||||
<< StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 4;
|
||||
}
|
||||
if(errorCode) {
|
||||
XMLPlatformUtils::Terminate();
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
if (!errorCount) {
|
||||
//
|
||||
// Now we will get an enumerator for the element pool from the validator
|
||||
// and enumerate the elements, printing them as we go. For each element
|
||||
// we get an enumerator for its attributes and print them also.
|
||||
//
|
||||
DTDGrammar* grammar = (DTDGrammar*) valToUse->getGrammar();
|
||||
NameIdPoolEnumerator<DTDElementDecl> elemEnum = grammar->getElemEnumerator();
|
||||
if (elemEnum.hasMoreElements())
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nELEMENTS:\n----------------------------\n";
|
||||
while(elemEnum.hasMoreElements())
|
||||
{
|
||||
const DTDElementDecl& curElem = elemEnum.nextElement();
|
||||
XERCES_STD_QUALIFIER cout << " Name: " << StrX(curElem.getFullName()) << "\n";
|
||||
|
||||
XERCES_STD_QUALIFIER cout << " Content Model: "
|
||||
<< StrX(curElem.getFormattedContentModel())
|
||||
<< "\n";
|
||||
|
||||
// Get an enumerator for this guy's attributes if any
|
||||
if (curElem.hasAttDefs())
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << " Attributes:\n";
|
||||
XMLAttDefList& attList = curElem.getAttDefList();
|
||||
for (unsigned int i=0; i<attList.getAttDefCount(); i++)
|
||||
{
|
||||
const XMLAttDef& curAttDef = attList.getAttDef(i);
|
||||
XERCES_STD_QUALIFIER cout << " Name:" << StrX(curAttDef.getFullName())
|
||||
<< ", Type: ";
|
||||
|
||||
// Get the type and display it
|
||||
const XMLAttDef::AttTypes type = curAttDef.getType();
|
||||
switch(type)
|
||||
{
|
||||
case XMLAttDef::CData :
|
||||
XERCES_STD_QUALIFIER cout << "CDATA";
|
||||
break;
|
||||
|
||||
case XMLAttDef::ID :
|
||||
XERCES_STD_QUALIFIER cout << "ID";
|
||||
break;
|
||||
|
||||
case XMLAttDef::IDRef :
|
||||
case XMLAttDef::IDRefs :
|
||||
XERCES_STD_QUALIFIER cout << "IDREF(S)";
|
||||
break;
|
||||
|
||||
case XMLAttDef::Entity :
|
||||
case XMLAttDef::Entities :
|
||||
XERCES_STD_QUALIFIER cout << "ENTITY(IES)";
|
||||
break;
|
||||
|
||||
case XMLAttDef::NmToken :
|
||||
case XMLAttDef::NmTokens :
|
||||
XERCES_STD_QUALIFIER cout << "NMTOKEN(S)";
|
||||
break;
|
||||
|
||||
case XMLAttDef::Notation :
|
||||
XERCES_STD_QUALIFIER cout << "NOTATION";
|
||||
break;
|
||||
|
||||
case XMLAttDef::Enumeration :
|
||||
XERCES_STD_QUALIFIER cout << "ENUMERATION";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
XERCES_STD_QUALIFIER cout << "\n";
|
||||
}
|
||||
}
|
||||
XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "The validator has no elements to display\n" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
XERCES_STD_QUALIFIER cout << "\nErrors occurred, no output available\n" << XERCES_STD_QUALIFIER endl;
|
||||
|
||||
//
|
||||
// Delete the parser itself. Must be done prior to calling Terminate, below.
|
||||
//
|
||||
delete parser;
|
||||
|
||||
// And call the termination method
|
||||
XMLPlatformUtils::Terminate();
|
||||
|
||||
if (errorCount > 0)
|
||||
return 4;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Executable
+288
@@ -0,0 +1,288 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* $Id: MemParse.cpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* This sample program illustrates how one can use a memory buffer as the
|
||||
* input to parser. The memory buffer contains raw bytes representing XML
|
||||
* statements.
|
||||
*
|
||||
* Look at the API documentation for 'MemBufInputSource' for more information
|
||||
* on parameters to the constructor.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/parsers/SAXParser.hpp>
|
||||
#include <xercesc/framework/MemBufInputSource.hpp>
|
||||
#include "MemParse.hpp"
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local const data
|
||||
//
|
||||
// gXMLInMemBuf
|
||||
// Defines the memory buffer contents here which parsed by the XML
|
||||
// parser. This is the cheap way to do it, instead of reading it from
|
||||
// somewhere. For this demo, its fine.
|
||||
//
|
||||
// NOTE: If your encoding is not ascii you will need to change
|
||||
// the MEMPARSE_ENCODING #define
|
||||
//
|
||||
// gMemBufId
|
||||
// A simple name to give as the system id for the memory buffer. This
|
||||
// just for indentification purposes in case of errors. Its not a real
|
||||
// system id (and the parser knows that.)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#ifndef MEMPARSE_ENCODING
|
||||
#if defined(OS390)
|
||||
#define MEMPARSE_ENCODING "ibm-1047-s390"
|
||||
#elif defined(OS400)
|
||||
#define MEMPARSE_ENCODING "ibm037"
|
||||
#else
|
||||
#define MEMPARSE_ENCODING "ascii"
|
||||
#endif
|
||||
#endif /* ifndef MEMPARSE_ENCODING */
|
||||
|
||||
static const char* gXMLInMemBuf =
|
||||
"\
|
||||
<?xml version='1.0' encoding='" MEMPARSE_ENCODING "'?>\n\
|
||||
<!DOCTYPE company [\n\
|
||||
<!ELEMENT company (product,category,developedAt)>\n\
|
||||
<!ELEMENT product (#PCDATA)>\n\
|
||||
<!ELEMENT category (#PCDATA)>\n\
|
||||
<!ATTLIST category idea CDATA #IMPLIED>\n\
|
||||
<!ELEMENT developedAt (#PCDATA)>\n\
|
||||
]>\n\n\
|
||||
<company>\n\
|
||||
<product>XML4C</product>\n\
|
||||
<category idea='great'>XML Parsing Tools</category>\n\
|
||||
<developedAt>\n\
|
||||
IBM Center for Java Technology, Silicon Valley, Cupertino, CA\n\
|
||||
</developedAt>\n\
|
||||
</company>\
|
||||
";
|
||||
|
||||
static const char* gMemBufId = "prodInfo";
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void usage()
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
||||
" MemParse [options]\n\n"
|
||||
"This program uses the SAX Parser to parse a memory buffer\n"
|
||||
"containing XML statements, and reports the number of\n"
|
||||
"elements and attributes found.\n\n"
|
||||
"Options:\n"
|
||||
" -v=xxx Validation scheme [always | never | auto*].\n"
|
||||
" -n Enable namespace processing. Defaults to off.\n"
|
||||
" -s Enable schema processing. Defaults to off.\n"
|
||||
" -f Enable full schema constraint checking. Defaults to off.\n"
|
||||
" -? Show this help.\n\n"
|
||||
" * = Default if not provided explicitly.\n"
|
||||
<< XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Program entry point
|
||||
// ---------------------------------------------------------------------------
|
||||
int main(int argC, char* argV[])
|
||||
{
|
||||
// Initialize the XML4C2 system
|
||||
try
|
||||
{
|
||||
XMLPlatformUtils::Initialize();
|
||||
}
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
|
||||
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
SAXParser::ValSchemes valScheme = SAXParser::Val_Auto;
|
||||
bool doNamespaces = false;
|
||||
bool doSchema = false;
|
||||
bool schemaFullChecking = false;
|
||||
|
||||
int argInd;
|
||||
for (argInd = 1; argInd < argC; argInd++)
|
||||
{
|
||||
// Break out on first parm not starting with a dash
|
||||
if (argV[argInd][0] != '-')
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Watch for special case help request
|
||||
if (!strcmp(argV[argInd], "-?"))
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 1;
|
||||
}
|
||||
else if (!strncmp(argV[argInd], "-v=", 3)
|
||||
|| !strncmp(argV[argInd], "-V=", 3))
|
||||
{
|
||||
const char* const parm = &argV[argInd][3];
|
||||
|
||||
if (!strcmp(parm, "never"))
|
||||
valScheme = SAXParser::Val_Never;
|
||||
else if (!strcmp(parm, "auto"))
|
||||
valScheme = SAXParser::Val_Auto;
|
||||
else if (!strcmp(parm, "always"))
|
||||
valScheme = SAXParser::Val_Always;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -v= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-n")
|
||||
|| !strcmp(argV[argInd], "-N"))
|
||||
{
|
||||
doNamespaces = true;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-s")
|
||||
|| !strcmp(argV[argInd], "-S"))
|
||||
{
|
||||
doSchema = true;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-f")
|
||||
|| !strcmp(argV[argInd], "-F"))
|
||||
{
|
||||
schemaFullChecking = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[argInd]
|
||||
<< "', ignoring it\n" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Create a SAX parser object. Then, according to what we were told on
|
||||
// the command line, set it to validate or not.
|
||||
//
|
||||
SAXParser* parser = new SAXParser;
|
||||
parser->setValidationScheme(valScheme);
|
||||
parser->setDoNamespaces(doNamespaces);
|
||||
parser->setDoSchema(doSchema);
|
||||
parser->setValidationSchemaFullChecking(schemaFullChecking);
|
||||
|
||||
//
|
||||
// Create our SAX handler object and install it on the parser, as the
|
||||
// document and error handlers.
|
||||
//
|
||||
MemParseHandlers handler;
|
||||
parser->setDocumentHandler(&handler);
|
||||
parser->setErrorHandler(&handler);
|
||||
|
||||
//
|
||||
// Create MemBufferInputSource from the buffer containing the XML
|
||||
// statements.
|
||||
//
|
||||
// NOTE: We are using strlen() here, since we know that the chars in
|
||||
// our hard coded buffer are single byte chars!!! The parameter wants
|
||||
// the number of BYTES, not chars, so when you create a memory buffer
|
||||
// give it the byte size (which just happens to be the same here.)
|
||||
//
|
||||
MemBufInputSource* memBufIS = new MemBufInputSource
|
||||
(
|
||||
(const XMLByte*)gXMLInMemBuf
|
||||
, strlen(gXMLInMemBuf)
|
||||
, gMemBufId
|
||||
, false
|
||||
);
|
||||
|
||||
//
|
||||
// Get the starting time and kick off the parse of the indicated
|
||||
// file. Catch any exceptions that might propogate out of it.
|
||||
//
|
||||
unsigned long duration;
|
||||
int errorCount = 0;
|
||||
int errorCode = 0;
|
||||
try
|
||||
{
|
||||
const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
|
||||
parser->parse(*memBufIS);
|
||||
const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
|
||||
duration = endMillis - startMillis;
|
||||
errorCount = parser->getErrorCount();
|
||||
}
|
||||
catch (const OutOfMemoryException&)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 5;
|
||||
}
|
||||
catch (const XMLException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError during parsing memory stream:\n"
|
||||
<< "Exception message is: \n"
|
||||
<< StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 4;
|
||||
}
|
||||
if(errorCode) {
|
||||
XMLPlatformUtils::Terminate();
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
// Print out the stats that we collected and time taken.
|
||||
if (!errorCount) {
|
||||
XERCES_STD_QUALIFIER cout << "\nFinished parsing the memory buffer containing the following "
|
||||
<< "XML statements:\n\n"
|
||||
<< gXMLInMemBuf
|
||||
<< "\n\n\n"
|
||||
<< "Parsing took " << duration << " ms ("
|
||||
<< handler.getElementCount() << " elements, "
|
||||
<< handler.getAttrCount() << " attributes, "
|
||||
<< handler.getSpaceCount() << " spaces, "
|
||||
<< handler.getCharacterCount() << " characters).\n" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
//
|
||||
// Delete the parser itself. Must be done prior to calling Terminate, below.
|
||||
//
|
||||
delete parser;
|
||||
|
||||
delete memBufIS;
|
||||
|
||||
// And call the termination method
|
||||
XMLPlatformUtils::Terminate();
|
||||
|
||||
if (errorCount > 0)
|
||||
return 4;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable
+85
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: MemParse.hpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes for all the program files to see
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include "MemParseHandlers.hpp"
|
||||
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple class that lets us do easy (though not terribly efficient)
|
||||
// trancoding of XMLCh data to local code page for display.
|
||||
// ---------------------------------------------------------------------------
|
||||
class StrX
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StrX(const XMLCh* const toTranscode)
|
||||
{
|
||||
// Call the private transcoding method
|
||||
fLocalForm = XMLString::transcode(toTranscode);
|
||||
}
|
||||
|
||||
~StrX()
|
||||
{
|
||||
XMLString::release(&fLocalForm);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
const char* localForm() const
|
||||
{
|
||||
return fLocalForm;
|
||||
}
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fLocalForm
|
||||
// This is the local code page form of the string.
|
||||
// -----------------------------------------------------------------------
|
||||
char* fLocalForm;
|
||||
};
|
||||
|
||||
inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
||||
{
|
||||
target << toDump.localForm();
|
||||
return target;
|
||||
}
|
||||
Executable
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: MemParseHandlers.cpp 557282 2007-07-18 14:54:15Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include "MemParse.hpp"
|
||||
#include <string.h>
|
||||
#include <xercesc/sax/AttributeList.hpp>
|
||||
#include <xercesc/sax/SAXParseException.hpp>
|
||||
#include <xercesc/sax/SAXException.hpp>
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// MemParseHandlers: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
MemParseHandlers::MemParseHandlers() :
|
||||
fAttrCount(0)
|
||||
, fCharacterCount(0)
|
||||
, fElementCount(0)
|
||||
, fSpaceCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
MemParseHandlers::~MemParseHandlers()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// MemParseHandlers: Implementation of the SAX DocumentHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void MemParseHandlers::startElement(const XMLCh* const /* name */
|
||||
, AttributeList& attributes)
|
||||
{
|
||||
fElementCount++;
|
||||
fAttrCount += attributes.getLength();
|
||||
}
|
||||
|
||||
void MemParseHandlers::characters( const XMLCh* const /* chars */
|
||||
, const XMLSize_t length)
|
||||
{
|
||||
fCharacterCount += length;
|
||||
}
|
||||
|
||||
void MemParseHandlers::ignorableWhitespace( const XMLCh* const /* chars */
|
||||
, const XMLSize_t length)
|
||||
{
|
||||
fSpaceCount += length;
|
||||
}
|
||||
|
||||
void MemParseHandlers::resetDocument()
|
||||
{
|
||||
fAttrCount = 0;
|
||||
fCharacterCount = 0;
|
||||
fElementCount = 0;
|
||||
fSpaceCount = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// MemParseHandlers: Overrides of the SAX ErrorHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void MemParseHandlers::error(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError at (file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void MemParseHandlers::fatalError(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nFatal Error at (file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void MemParseHandlers::warning(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nWarning at (file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
|
||||
Executable
+102
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: MemParseHandlers.hpp 679377 2008-07-24 11:56:42Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/sax/HandlerBase.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
class AttributeList;
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
|
||||
class MemParseHandlers : public HandlerBase
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
MemParseHandlers();
|
||||
~MemParseHandlers();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t getElementCount()
|
||||
{
|
||||
return fElementCount;
|
||||
}
|
||||
|
||||
XMLSize_t getAttrCount()
|
||||
{
|
||||
return fAttrCount;
|
||||
}
|
||||
|
||||
XMLSize_t getCharacterCount()
|
||||
{
|
||||
return fCharacterCount;
|
||||
}
|
||||
|
||||
XMLSize_t getSpaceCount()
|
||||
{
|
||||
return fSpaceCount;
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the SAX DocumentHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void startElement(const XMLCh* const name, AttributeList& attributes);
|
||||
void characters(const XMLCh* const chars, const XMLSize_t length);
|
||||
void ignorableWhitespace(const XMLCh* const chars, const XMLSize_t length);
|
||||
void resetDocument();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the SAX ErrorHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void warning(const SAXParseException& exc);
|
||||
void error(const SAXParseException& exc);
|
||||
void fatalError(const SAXParseException& exc);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fAttrCount
|
||||
// fCharacterCount
|
||||
// fElementCount
|
||||
// fSpaceCount
|
||||
// These are just counters that are run upwards based on the input
|
||||
// from the document handlers.
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t fAttrCount;
|
||||
XMLSize_t fCharacterCount;
|
||||
XMLSize_t fElementCount;
|
||||
XMLSize_t fSpaceCount;
|
||||
};
|
||||
Executable
+294
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: PParse.cpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This sample program demonstrates the progressive parse capabilities of
|
||||
// the parser system. It allows you to do a scanFirst() call followed by
|
||||
// a loop which calls scanNext(). You can drop out when you've found what
|
||||
// ever it is you want. In our little test, our event handler looks for
|
||||
// 16 new elements then sets a flag to indicate its found what it wants.
|
||||
// At that point, our progressive parse loop below exits.
|
||||
//
|
||||
// The parameters are:
|
||||
//
|
||||
// [-?] - Show usage and exit
|
||||
// [-v=xxx] - Validation scheme [always | never | auto*]
|
||||
// [-n] - Enable namespace processing
|
||||
// [-s] - Enable schema processing
|
||||
// [-f] - Enable full schema constraint checking
|
||||
// filename - The path to the XML file to parse
|
||||
//
|
||||
// * = Default if not provided explicitly
|
||||
// These are non-case sensitive
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/framework/XMLPScanToken.hpp>
|
||||
#include <xercesc/parsers/SAXParser.hpp>
|
||||
#include "PParse.hpp"
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local data
|
||||
//
|
||||
// xmlFile
|
||||
// The path to the file to parser. Set via command line.
|
||||
//
|
||||
// doNamespaces
|
||||
// Indicates whether namespace processing should be done.
|
||||
//
|
||||
// doSchema
|
||||
// Indicates whether schema processing should be done.
|
||||
//
|
||||
// schemaFullChecking
|
||||
// Indicates whether full schema constraint checking should be done.
|
||||
//
|
||||
// valScheme
|
||||
// Indicates what validation scheme to use. It defaults to 'auto', but
|
||||
// can be set via the -v= command.
|
||||
// ---------------------------------------------------------------------------
|
||||
static char* xmlFile = 0;
|
||||
static bool doNamespaces = false;
|
||||
static bool doSchema = false;
|
||||
static bool schemaFullChecking = false;
|
||||
static SAXParser::ValSchemes valScheme = SAXParser::Val_Auto;
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
static void usage()
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
||||
" PParse [options] <XML file>\n\n"
|
||||
"This program demonstrates the progressive parse capabilities of\n"
|
||||
"the parser system. It allows you to do a scanFirst() call followed by\n"
|
||||
"a loop which calls scanNext(). You can drop out when you've found what\n"
|
||||
"ever it is you want. In our little test, our event handler looks for\n"
|
||||
"16 new elements then sets a flag to indicate its found what it wants.\n"
|
||||
"At that point, our progressive parse loop exits.\n\n"
|
||||
"Options:\n"
|
||||
" -v=xxx - Validation scheme [always | never | auto*].\n"
|
||||
" -n - Enable namespace processing [default is off].\n"
|
||||
" -s - Enable schema processing [default is off].\n"
|
||||
" -f - Enable full schema constraint checking [default is off].\n"
|
||||
" -? - Show this help.\n\n"
|
||||
" * = Default if not provided explicitly.\n"
|
||||
<< XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Program entry point
|
||||
// ---------------------------------------------------------------------------
|
||||
int main(int argC, char* argV[])
|
||||
{
|
||||
// Initialize the XML4C system
|
||||
try
|
||||
{
|
||||
XMLPlatformUtils::Initialize();
|
||||
}
|
||||
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Error during initialization! :\n"
|
||||
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check command line and extract arguments.
|
||||
if (argC < 2)
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// See if non validating dom parser configuration is requested.
|
||||
int parmInd;
|
||||
for (parmInd = 1; parmInd < argC; parmInd++)
|
||||
{
|
||||
// Break out on first parm not starting with a dash
|
||||
if (argV[parmInd][0] != '-')
|
||||
break;
|
||||
|
||||
// Watch for special case help request
|
||||
if (!strcmp(argV[parmInd], "-?"))
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-v=", 3)
|
||||
|| !strncmp(argV[parmInd], "-V=", 3))
|
||||
{
|
||||
const char* const parm = &argV[parmInd][3];
|
||||
|
||||
if (!strcmp(parm, "never"))
|
||||
valScheme = SAXParser::Val_Never;
|
||||
else if (!strcmp(parm, "auto"))
|
||||
valScheme = SAXParser::Val_Auto;
|
||||
else if (!strcmp(parm, "always"))
|
||||
valScheme = SAXParser::Val_Always;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -v= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-n")
|
||||
|| !strcmp(argV[parmInd], "-N"))
|
||||
{
|
||||
doNamespaces = true;
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-s")
|
||||
|| !strcmp(argV[parmInd], "-S"))
|
||||
{
|
||||
doSchema = true;
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-f")
|
||||
|| !strcmp(argV[parmInd], "-F"))
|
||||
{
|
||||
schemaFullChecking = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[parmInd]
|
||||
<< "', ignoring it\n" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// And now we have to have only one parameter left and it must be
|
||||
// the file name.
|
||||
//
|
||||
if (parmInd + 1 != argC)
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 1;
|
||||
}
|
||||
xmlFile = argV[parmInd];
|
||||
int errorCount = 0;
|
||||
|
||||
//
|
||||
// Create a SAX parser object to use and create our SAX event handlers
|
||||
// and plug them in.
|
||||
//
|
||||
SAXParser* parser = new SAXParser;
|
||||
PParseHandlers handler;
|
||||
parser->setDocumentHandler(&handler);
|
||||
parser->setErrorHandler(&handler);
|
||||
parser->setValidationScheme(valScheme);
|
||||
parser->setDoNamespaces(doNamespaces);
|
||||
parser->setDoSchema(doSchema);
|
||||
parser->setValidationSchemaFullChecking(schemaFullChecking);
|
||||
|
||||
//
|
||||
// Ok, lets do the progressive parse loop. On each time around the
|
||||
// loop, we look and see if the handler has found what its looking
|
||||
// for. When it does, we fall out then.
|
||||
//
|
||||
unsigned long duration;
|
||||
int errorCode = 0;
|
||||
try
|
||||
{
|
||||
// Create a progressive scan token
|
||||
XMLPScanToken token;
|
||||
|
||||
const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
|
||||
if (!parser->parseFirst(xmlFile, token))
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "scanFirst() failed\n" << XERCES_STD_QUALIFIER endl;
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 1;
|
||||
}
|
||||
|
||||
//
|
||||
// We started ok, so lets call scanNext() until we find what we want
|
||||
// or hit the end.
|
||||
//
|
||||
bool gotMore = true;
|
||||
while (gotMore && !parser->getErrorCount())
|
||||
gotMore = parser->parseNext(token);
|
||||
|
||||
const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
|
||||
duration = endMillis - startMillis;
|
||||
|
||||
errorCount = parser->getErrorCount();
|
||||
//
|
||||
// Reset the parser-> In this simple progrma, since we just exit
|
||||
// now, its not technically required. But, in programs which
|
||||
// would remain open, you should reset after a progressive parse
|
||||
// in case you broke out before the end of the file. This insures
|
||||
// that all opened files, sockets, etc... are closed.
|
||||
//
|
||||
parser->parseReset(token);
|
||||
}
|
||||
catch (const OutOfMemoryException&)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 5;
|
||||
}
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nAn error occurred: '" << xmlFile << "'\n"
|
||||
<< "Exception message is: \n"
|
||||
<< StrX(toCatch.getMessage())
|
||||
<< "\n" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 4;
|
||||
}
|
||||
|
||||
if(errorCode) {
|
||||
XMLPlatformUtils::Terminate();
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
if (!errorCount) {
|
||||
XERCES_STD_QUALIFIER cout << xmlFile << ": " << duration << " ms ("
|
||||
<< handler.getElementCount() << " elems, "
|
||||
<< handler.getAttrCount() << " attrs, "
|
||||
<< handler.getSpaceCount() << " spaces, "
|
||||
<< handler.getCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
//
|
||||
// Delete the parser itself. Must be done prior to calling Terminate, below.
|
||||
//
|
||||
delete parser;
|
||||
|
||||
// And call the termination method
|
||||
XMLPlatformUtils::Terminate();
|
||||
|
||||
if (errorCount > 0)
|
||||
return 4;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: PParse.hpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes for all the program files to see
|
||||
// ---------------------------------------------------------------------------
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "PParseHandlers.hpp"
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple class that lets us do easy (though not terribly efficient)
|
||||
// trancoding of XMLCh data to local code page for display.
|
||||
// ---------------------------------------------------------------------------
|
||||
class StrX
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StrX(const XMLCh* const toTranscode)
|
||||
{
|
||||
// Call the private transcoding method
|
||||
fLocalForm = XMLString::transcode(toTranscode);
|
||||
}
|
||||
|
||||
~StrX()
|
||||
{
|
||||
XMLString::release(&fLocalForm);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
const char* localForm() const
|
||||
{
|
||||
return fLocalForm;
|
||||
}
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fLocalForm
|
||||
// This is the local code page form of the string.
|
||||
// -----------------------------------------------------------------------
|
||||
char* fLocalForm;
|
||||
};
|
||||
|
||||
inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
||||
{
|
||||
target << toDump.localForm();
|
||||
return target;
|
||||
}
|
||||
Executable
+107
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: PParseHandlers.cpp 557282 2007-07-18 14:54:15Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/XMLUniDefs.hpp>
|
||||
#include <xercesc/util/XMLUni.hpp>
|
||||
#include <xercesc/sax/AttributeList.hpp>
|
||||
#include "PParse.hpp"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// PParseHandlers: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
PParseHandlers::PParseHandlers() :
|
||||
|
||||
fAttrCount(0)
|
||||
, fCharacterCount(0)
|
||||
, fElementCount(0)
|
||||
, fSpaceCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
PParseHandlers::~PParseHandlers()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// PParseHandlers: Overrides of the SAX DocumentHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void PParseHandlers::startElement(const XMLCh* const /* name */
|
||||
, AttributeList& attributes)
|
||||
{
|
||||
fElementCount++;
|
||||
fAttrCount += attributes.getLength();
|
||||
}
|
||||
|
||||
void PParseHandlers::characters( const XMLCh* const /* chars */
|
||||
, const XMLSize_t length)
|
||||
{
|
||||
fCharacterCount += length;
|
||||
}
|
||||
|
||||
void PParseHandlers::ignorableWhitespace( const XMLCh* const /* chars */
|
||||
, const XMLSize_t length)
|
||||
{
|
||||
fSpaceCount += length;
|
||||
}
|
||||
|
||||
void PParseHandlers::resetDocument()
|
||||
{
|
||||
fAttrCount = 0;
|
||||
fCharacterCount = 0;
|
||||
fElementCount = 0;
|
||||
fSpaceCount = 0;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// PParseHandlers: Overrides of the SAX ErrorHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void PParseHandlers::error(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void PParseHandlers::fatalError(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nFatal Error at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void PParseHandlers::warning(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nWarning at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
Executable
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: PParseHandlers.hpp 679377 2008-07-24 11:56:42Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
#include <xercesc/sax/HandlerBase.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
class PParseHandlers : public HandlerBase
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors
|
||||
// -----------------------------------------------------------------------
|
||||
PParseHandlers();
|
||||
~PParseHandlers();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t getElementCount() const
|
||||
{
|
||||
return fElementCount;
|
||||
}
|
||||
|
||||
XMLSize_t getAttrCount() const
|
||||
{
|
||||
return fAttrCount;
|
||||
}
|
||||
|
||||
XMLSize_t getCharacterCount() const
|
||||
{
|
||||
return fCharacterCount;
|
||||
}
|
||||
|
||||
bool getSawErrors() const
|
||||
{
|
||||
return fSawErrors;
|
||||
}
|
||||
|
||||
XMLSize_t getSpaceCount() const
|
||||
{
|
||||
return fSpaceCount;
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the SAX DocumentHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void startElement(const XMLCh* const name, AttributeList& attributes);
|
||||
void characters(const XMLCh* const chars, const XMLSize_t length);
|
||||
void ignorableWhitespace(const XMLCh* const chars, const XMLSize_t length);
|
||||
void resetDocument();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementations of the SAX ErrorHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void warning(const SAXParseException& exc);
|
||||
void error(const SAXParseException& exc);
|
||||
void fatalError(const SAXParseException& exc);
|
||||
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fAttrCount
|
||||
// fCharacterCount
|
||||
// fElementCount
|
||||
// fSpaceCount
|
||||
// These are just counters that are run upwards based on the input
|
||||
// from the document handlers.
|
||||
//
|
||||
// fSawErrors
|
||||
// This is set by the error handlers, and is queryable later to
|
||||
// see if any errors occured.
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t fAttrCount;
|
||||
XMLSize_t fCharacterCount;
|
||||
XMLSize_t fElementCount;
|
||||
XMLSize_t fSpaceCount;
|
||||
bool fSawErrors;
|
||||
};
|
||||
|
||||
Executable
+347
@@ -0,0 +1,347 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//REVISIT
|
||||
/*
|
||||
* $Id: PSVIWriter.cpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include "PSVIWriter.hpp"
|
||||
#include <xercesc/framework/StdOutFormatTarget.hpp>
|
||||
#include <xercesc/framework/LocalFileFormatTarget.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/TransService.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/parsers/SAX2XMLReaderImpl.hpp>
|
||||
#include <xercesc/sax2/XMLReaderFactory.hpp>
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <fstream>
|
||||
#else
|
||||
#include <fstream.h>
|
||||
#endif
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void usage()
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
||||
" PSVIWriter [options] <XML file | List file>\n\n"
|
||||
"This program invokes the SAX2XMLReaderImpl, and then exposes the\n"
|
||||
"underlying PSVI of each parsed XML file, using SAX2 API.\n\n"
|
||||
"Options:\n"
|
||||
" -f Enable full schema constraint checking processing. Defaults to off.\n"
|
||||
" -o=xxx Output PSVI to file xxx (default is stdout)\n"
|
||||
" -e=xxx Output errors to file xxx (default is stdout)\n"
|
||||
" -u=xxx Handle unrepresentable chars [fail | rep | ref*].\n"
|
||||
" -x=XXX Use a particular encoding for output (UTF8*).\n"
|
||||
" -l Indicate the input file is a List File that has a list of xml files.\n"
|
||||
" Default to off (Input file is an XML file).\n"
|
||||
" -? Show this help.\n\n"
|
||||
" * = Default if not provided explicitly.\n"
|
||||
<< XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Program entry point
|
||||
// ---------------------------------------------------------------------------
|
||||
int main(int argC, char* argV[])
|
||||
{
|
||||
|
||||
// Check command line and extract arguments.
|
||||
if (argC < 2)
|
||||
{
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char* encodingName = "UTF8";
|
||||
static XMLFormatter::UnRepFlags unRepFlags = XMLFormatter::UnRep_CharRef;
|
||||
const char* xmlFile = 0;
|
||||
bool doList = false; //REVISIT
|
||||
bool schemaFullChecking = false;
|
||||
bool errorOccurred = false;
|
||||
const char* psviOut = 0;
|
||||
const char* errorOut = 0;
|
||||
XMLFormatTarget* psviTarget = 0;
|
||||
XMLFormatTarget* errorTarget = 0;
|
||||
XMLFormatter* psviFormatter = 0;
|
||||
XMLFormatter* errorFormatter = 0;
|
||||
char fileName[80] ="";
|
||||
|
||||
|
||||
int argInd;
|
||||
for (argInd = 1; argInd < argC; argInd++)
|
||||
{
|
||||
// Break out on first parm not starting with a dash
|
||||
if (argV[argInd][0] != '-')
|
||||
break;
|
||||
|
||||
// Watch for special case help request
|
||||
if (!strcmp(argV[argInd], "-?"))
|
||||
{
|
||||
usage();
|
||||
return 2;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-l")
|
||||
|| !strcmp(argV[argInd], "-L"))
|
||||
{
|
||||
doList = true;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-f")
|
||||
|| !strcmp(argV[argInd], "-F"))
|
||||
{
|
||||
schemaFullChecking = true;
|
||||
}
|
||||
else if (!strncmp(argV[argInd], "-o=", 3)
|
||||
|| !strncmp(argV[argInd], "-O=", 3))
|
||||
{
|
||||
psviOut = &argV[argInd][3];
|
||||
}
|
||||
else if (!strncmp(argV[argInd], "-e=", 3)
|
||||
|| !strncmp(argV[argInd], "-E=", 3))
|
||||
{
|
||||
errorOut = &argV[argInd][3];
|
||||
}
|
||||
else if (!strncmp(argV[argInd], "-x=", 3)
|
||||
|| !strncmp(argV[argInd], "-X=", 3))
|
||||
{
|
||||
// Get out the encoding name
|
||||
encodingName = &argV[argInd][3];
|
||||
}
|
||||
else if (!strncmp(argV[argInd], "-u=", 3)
|
||||
|| !strncmp(argV[argInd], "-U=", 3))
|
||||
{
|
||||
const char* const parm = &argV[argInd][3];
|
||||
|
||||
if (!strcmp(parm, "fail"))
|
||||
unRepFlags = XMLFormatter::UnRep_Fail;
|
||||
else if (!strcmp(parm, "rep"))
|
||||
unRepFlags = XMLFormatter::UnRep_Replace;
|
||||
else if (!strcmp(parm, "ref"))
|
||||
unRepFlags = XMLFormatter::UnRep_CharRef;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -u= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[argInd]
|
||||
<< "', ignoring it\n" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// There should be only one and only one parameter left, and that
|
||||
// should be the file name.
|
||||
//
|
||||
if (argInd != argC - 1)
|
||||
{
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Initialize the XML4C2 system
|
||||
try
|
||||
{
|
||||
XMLPlatformUtils::Initialize();
|
||||
} catch (const XMLException& toCatch) {
|
||||
XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
|
||||
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Create a SAX parser object, then set it to validate or not.
|
||||
//
|
||||
SAX2XMLReaderImpl* parser = new SAX2XMLReaderImpl();
|
||||
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
|
||||
parser->setFeature(XMLUni::fgXercesSchema, true);
|
||||
parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
|
||||
parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, false);
|
||||
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
|
||||
parser->setFeature(XMLUni::fgXercesDynamic, true);
|
||||
|
||||
//
|
||||
// Based on commandline arguments, create XMLFormatters for PSVI output and errors
|
||||
//
|
||||
if (!doList) {
|
||||
if (psviOut==0) {
|
||||
psviTarget = new StdOutFormatTarget();
|
||||
} else {
|
||||
psviTarget = new LocalFileFormatTarget(psviOut);
|
||||
}
|
||||
psviFormatter = new XMLFormatter(encodingName, psviTarget, XMLFormatter::NoEscapes, unRepFlags);
|
||||
}
|
||||
|
||||
if (errorOut==0) {
|
||||
errorTarget = new StdOutFormatTarget();
|
||||
} else {
|
||||
errorTarget = new LocalFileFormatTarget(errorOut);
|
||||
}
|
||||
errorFormatter = new XMLFormatter(encodingName, errorTarget, XMLFormatter::NoEscapes, unRepFlags);
|
||||
|
||||
//
|
||||
// Create our SAX handler object and install it as the handlers
|
||||
//
|
||||
|
||||
PSVIWriterHandlers* handler;
|
||||
if (doList)
|
||||
handler = new PSVIWriterHandlers(0, errorFormatter);
|
||||
else
|
||||
handler = new PSVIWriterHandlers(psviFormatter, errorFormatter);
|
||||
|
||||
PSVIAdvancedHandler* advancedHandler = new PSVIAdvancedHandler(handler);
|
||||
parser->installAdvDocHandler(advancedHandler);
|
||||
|
||||
parser->setPSVIHandler(handler);
|
||||
parser->setContentHandler(handler);
|
||||
parser->setLexicalHandler(handler);
|
||||
parser->setXMLEntityResolver(handler);
|
||||
parser->setErrorHandler(handler);
|
||||
|
||||
//
|
||||
// Get the starting time and kick off the parse of the indicated
|
||||
// file. Catch any exceptions that might propogate out of it.
|
||||
//
|
||||
unsigned long duration;
|
||||
|
||||
bool more = true;
|
||||
XERCES_STD_QUALIFIER ifstream fin;
|
||||
|
||||
// the input is a list file
|
||||
if (doList) //REVISIT
|
||||
fin.open(argV[argInd]);
|
||||
|
||||
if (fin.fail()) {
|
||||
XERCES_STD_QUALIFIER cerr <<"Cannot open the list file: " << argV[argInd] << XERCES_STD_QUALIFIER endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
while (more) //REVISIT
|
||||
{
|
||||
char fURI[1000];
|
||||
//initialize the array to zeros
|
||||
memset(fURI,0,sizeof(fURI));
|
||||
|
||||
if (doList) {
|
||||
if (! fin.eof() ) {
|
||||
fin.getline (fURI, sizeof(fURI));
|
||||
if (!*fURI)
|
||||
continue;
|
||||
else {
|
||||
xmlFile =fURI;
|
||||
XMLString::trim((char*)xmlFile);
|
||||
XERCES_STD_QUALIFIER cerr << "==Parsing== \"" << xmlFile << "\"" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
if (psviOut==0) {
|
||||
if (psviTarget==0 && psviFormatter==0) {
|
||||
psviTarget = new StdOutFormatTarget();
|
||||
psviFormatter = new XMLFormatter(encodingName, psviTarget, XMLFormatter::NoEscapes, unRepFlags);
|
||||
handler->resetPSVIFormatter(psviFormatter);
|
||||
}
|
||||
} else {
|
||||
strcpy(fileName, psviOut);
|
||||
if (strrchr(xmlFile, '\\')>strrchr(xmlFile, '/')) {
|
||||
strcat(fileName, strrchr(xmlFile, '\\'));
|
||||
} else {
|
||||
strcat(fileName, strrchr(xmlFile, '/'));
|
||||
}
|
||||
if (psviFormatter)
|
||||
delete psviFormatter;
|
||||
if (psviTarget)
|
||||
delete psviTarget;
|
||||
psviTarget = new LocalFileFormatTarget(fileName);
|
||||
psviFormatter = new XMLFormatter(encodingName, psviTarget, XMLFormatter::NoEscapes, unRepFlags);
|
||||
handler->resetPSVIFormatter(psviFormatter);
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
else {
|
||||
xmlFile = argV[argInd];
|
||||
more = false; //REVISIT
|
||||
}
|
||||
|
||||
//reset error count first
|
||||
handler->resetErrors();
|
||||
|
||||
try
|
||||
{
|
||||
const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
|
||||
parser->parse(xmlFile);
|
||||
const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
|
||||
duration = endMillis - startMillis;
|
||||
}
|
||||
catch (const OutOfMemoryException&)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
|
||||
errorOccurred = true;
|
||||
continue;
|
||||
}
|
||||
catch (const XMLException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << xmlFile << "'\n"
|
||||
<< "Exception message is: \n"
|
||||
<< StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
|
||||
errorOccurred = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
catch (...)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nUnexpected exception during parsing: '" << xmlFile << "'\n" << XERCES_STD_QUALIFIER endl;;
|
||||
errorOccurred = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (doList) //REVISIT
|
||||
fin.close();
|
||||
|
||||
//
|
||||
// Delete the parser itself. Must be done prior to calling Terminate, below.
|
||||
//
|
||||
delete parser;
|
||||
delete advancedHandler;
|
||||
delete handler;
|
||||
delete psviFormatter;
|
||||
delete errorFormatter;
|
||||
delete psviTarget;
|
||||
delete errorTarget;
|
||||
|
||||
// And call the termination method
|
||||
XMLPlatformUtils::Terminate();
|
||||
|
||||
if (errorOccurred)
|
||||
return 4;
|
||||
else
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
Executable
+85
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#if !defined(PSVIWRITER_HPP)
|
||||
#define PSVIWRITER_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes for all the program files to see
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include "PSVIWriterHandlers.hpp"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/XMLUni.hpp>
|
||||
#include <xercesc/sax2/XMLReaderFactory.hpp>
|
||||
#include <xercesc/sax2/SAX2XMLReader.hpp>
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple class that lets us do easy (though not terribly efficient)
|
||||
// trancoding of XMLCh data to local code page for display.
|
||||
// ---------------------------------------------------------------------------
|
||||
class StrX
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StrX(const XMLCh* const toTranscode)
|
||||
{
|
||||
// Call the private transcoding method
|
||||
fLocalForm = XMLString::transcode(toTranscode);
|
||||
}
|
||||
|
||||
~StrX()
|
||||
{
|
||||
XMLString::release(&fLocalForm);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
const char* localForm() const
|
||||
{
|
||||
return fLocalForm;
|
||||
}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fLocalForm
|
||||
// This is the local code page form of the string.
|
||||
// -----------------------------------------------------------------------
|
||||
char* fLocalForm;
|
||||
};
|
||||
|
||||
inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
||||
{
|
||||
target << toDump.localForm();
|
||||
return target;
|
||||
}
|
||||
|
||||
#endif
|
||||
+1971
File diff suppressed because it is too large
Load Diff
+308
@@ -0,0 +1,308 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef PSVIWRITERHANDLER_HPP
|
||||
#define PSVIWRITERHANDLER_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/sax2/Attributes.hpp>
|
||||
#include <xercesc/sax2/DefaultHandler.hpp>
|
||||
#include <xercesc/framework/psvi/XSConstants.hpp>
|
||||
#include <xercesc/framework/psvi/PSVIHandler.hpp>
|
||||
#include <xercesc/framework/psvi/PSVIAttribute.hpp>
|
||||
#include <xercesc/framework/psvi/PSVIAttributeList.hpp>
|
||||
#include <xercesc/framework/psvi/PSVIElement.hpp>
|
||||
#include <xercesc/framework/psvi/PSVIItem.hpp>
|
||||
#include <xercesc/framework/psvi/XSAnnotation.hpp>
|
||||
#include <xercesc/framework/psvi/XSAttributeDeclaration.hpp>
|
||||
#include <xercesc/framework/psvi/XSAttributeGroupDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSAttributeUse.hpp>
|
||||
#include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSElementDeclaration.hpp>
|
||||
#include <xercesc/framework/psvi/XSFacet.hpp>
|
||||
#include <xercesc/framework/psvi/XSIDCDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSModel.hpp>
|
||||
#include <xercesc/framework/psvi/XSModelGroup.hpp>
|
||||
#include <xercesc/framework/psvi/XSModelGroupDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSMultiValueFacet.hpp>
|
||||
#include <xercesc/framework/psvi/XSNamedMap.hpp>
|
||||
#include <xercesc/framework/psvi/XSNamespaceItem.hpp>
|
||||
#include <xercesc/framework/psvi/XSNotationDeclaration.hpp>
|
||||
#include <xercesc/framework/psvi/XSParticle.hpp>
|
||||
#include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSTypeDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSWildcard.hpp>
|
||||
#include <xercesc/framework/XMLFormatter.hpp>
|
||||
#include <xercesc/framework/XMLDocumentHandler.hpp>
|
||||
#include <xercesc/dom/DOMElement.hpp>
|
||||
#include <xercesc/dom/DOMNamedNodeMap.hpp>
|
||||
#include <xercesc/util/ValueStackOf.hpp>
|
||||
#include <xercesc/util/ValueVectorOf.hpp>
|
||||
#include <xercesc/util/XMLEntityResolver.hpp>
|
||||
#include <xercesc/util/XMLResourceIdentifier.hpp>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
|
||||
class AttrInfo {
|
||||
public:
|
||||
AttrInfo(const XMLCh* pUri, const XMLCh* pName, const XMLCh* pType, const XMLCh* pValue) {
|
||||
uri = XMLString::replicate(pUri);
|
||||
name = XMLString::replicate(pName);
|
||||
type = XMLString::replicate(pType);
|
||||
value = XMLString::replicate(pValue);
|
||||
}
|
||||
|
||||
~AttrInfo() {
|
||||
XMLString::release((XMLCh**)&uri);
|
||||
XMLString::release((XMLCh**)&name);
|
||||
XMLString::release((XMLCh**)&type);
|
||||
XMLString::release((XMLCh**)&value);
|
||||
}
|
||||
|
||||
const XMLCh* getUri() const {
|
||||
return uri;
|
||||
}
|
||||
|
||||
const XMLCh* getLocalName() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
const XMLCh* getType() const {
|
||||
return type;
|
||||
}
|
||||
|
||||
const XMLCh* getValue() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
private:
|
||||
const XMLCh* uri;
|
||||
const XMLCh* name;
|
||||
const XMLCh* type;
|
||||
const XMLCh* value;
|
||||
};
|
||||
|
||||
class PSVIWriterHandlers : public PSVIHandler, public DefaultHandler, public XMLEntityResolver {
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
PSVIWriterHandlers(XMLFormatter* outputFormatter, XMLFormatter* errorFormatter = NULL);
|
||||
~PSVIWriterHandlers();
|
||||
|
||||
friend class PSVIAdvancedHandler;
|
||||
// -----------------------------------------------------------------------
|
||||
// Convenience Utility
|
||||
// -----------------------------------------------------------------------
|
||||
void resetPSVIFormatter(XMLFormatter* outputFormatter);
|
||||
void resetDocument();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the SAX ContentHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs);
|
||||
void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname);
|
||||
void startDocument();
|
||||
void endDocument();
|
||||
void characters(const XMLCh* const chars, const XMLSize_t length);
|
||||
void ignorableWhitespace(const XMLCh* const chars, const XMLSize_t length);
|
||||
void comment(const XMLCh* const chars, const XMLSize_t length);
|
||||
void processingInstruction(const XMLCh* const target, const XMLCh* const data);
|
||||
void startPrefixMapping(const XMLCh* const prefix, const XMLCh* const uri);
|
||||
void endPrefixMapping(const XMLCh* const prefix);
|
||||
InputSource* resolveEntity(XMLResourceIdentifier* resourceIdentifier);
|
||||
InputSource* resolveEntity(const XMLCh* const publicId, const XMLCh* const systemId);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the SAX ErrorHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void warning(const SAXParseException& exc);
|
||||
void error(const SAXParseException& exc);
|
||||
void fatalError(const SAXParseException& exc);
|
||||
void resetErrors();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the PSVIHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
void handleAttributesPSVI( const XMLCh* const localName,
|
||||
const XMLCh* const uri,
|
||||
PSVIAttributeList* psviAttributes );
|
||||
void handleElementPSVI( const XMLCh* const localName,
|
||||
const XMLCh* const uri,
|
||||
PSVIElement* elementInfo );
|
||||
void handlePartialElementPSVI( const XMLCh* const localName,
|
||||
const XMLCh* const uri,
|
||||
PSVIElement* elementInfo );
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Private methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
void processAttributes(PSVIAttributeList* psviAttributes, const RefVectorOf<AttrInfo>* attributesInfo);
|
||||
void processNamespaceAttributes(PSVIAttributeList* psviAttributes, const RefVectorOf<AttrInfo>* attributes);
|
||||
void processAttributePSVI(PSVIAttribute* attribute);
|
||||
void processInScopeNamespaces();
|
||||
void processActualValue(PSVIItem*);
|
||||
void formDateTime(XSValue*);
|
||||
|
||||
void processSchemaInformation(XSModel* model);
|
||||
void processNamespaceItem(XSNamespaceItem* namespaceItem);
|
||||
void processSchemaComponents(XSNamespaceItem* namespaceItem);
|
||||
void processSchemaDocuments(XSNamespaceItem* namespaceItem);
|
||||
void processSchemaAnnotations(XSAnnotationList* annotations);
|
||||
void processSchemaErrorCode(StringList* errors);
|
||||
|
||||
void processTypeDefinition(XSTypeDefinition* type);
|
||||
void processComplexTypeDefinition(XSComplexTypeDefinition* complexType);
|
||||
void processSimpleTypeDefinition(XSSimpleTypeDefinition* simpleType);
|
||||
void processModelGroupDefinition(XSModelGroupDefinition* modelGroup);
|
||||
void processAttributeGroupDefinition(XSAttributeGroupDefinition* attributeGroup);
|
||||
|
||||
void processElementDeclaration(XSElementDeclaration* element);
|
||||
void processAttributeDeclaration(XSAttributeDeclaration* attribute);
|
||||
void processNotationDeclaration(XSNotationDeclaration* notation);
|
||||
|
||||
void processAnnotations(XSAnnotationList* annotations);
|
||||
void processAttributeUses(XSAttributeUseList* attributeUses);
|
||||
void processFacets(XSFacetList* facets, XSMultiValueFacetList* multiFacets);
|
||||
void processFundamentalFacets(XSSimpleTypeDefinition* facets);
|
||||
void processMemberTypeDefinitions(XSSimpleTypeDefinitionList* memberTypes);
|
||||
|
||||
void processAnnotation(XSAnnotation* annotation);
|
||||
void processDOMElement(const XMLCh* const encloseName, DOMElement* rootElem, const XMLCh* const elementName);
|
||||
void processDOMAttributes(DOMNamedNodeMap* attrs);
|
||||
void processWildcard(XSWildcard* wildcard);
|
||||
void processModelGroup(XSModelGroup* modelGroup);
|
||||
void processParticle(XSParticle* particle);
|
||||
|
||||
void processAttributeWildcard(XSWildcard* wildcard);
|
||||
void processScope(XSComplexTypeDefinition* enclosingCTD, short scope);
|
||||
void processValueConstraint(XSConstants::VALUE_CONSTRAINT ConstraintType, const XMLCh* constraintValue);
|
||||
|
||||
void processIdentityConstraintDefinition(XSNamedMap<XSIDCDefinition>* identityConstraint);
|
||||
void processFields(StringList* fields);
|
||||
void processXPath(const XMLCh* xpath);
|
||||
|
||||
void processChildren();
|
||||
void processChildrenEnd();
|
||||
|
||||
void processTypeDefinitionOrRef(const XMLCh* enclose, XSTypeDefinition* type);
|
||||
void processSimpleTypeDefinitionOrRef(XSSimpleTypeDefinition* type);
|
||||
void processAttributeDeclarationOrRef(XSAttributeDeclaration* attrDecl);
|
||||
void processElementDeclarationOrRef(XSElementDeclaration* elemDecl);
|
||||
void processTypeDefinitionRef(const XMLCh* enclose, XSTypeDefinition* type);
|
||||
void processAttributeDeclarationRef(const XMLCh* enclose, XSAttributeDeclaration* attrDecl);
|
||||
void processElementDeclarationRef(const XMLCh* enclose, XSElementDeclaration* elemDecl);
|
||||
void sendReference(const XMLCh* elementName, XSObject* obj);
|
||||
|
||||
void sendElementEmpty(const XMLCh* const elementName);
|
||||
void sendElementValueInt(const XMLCh* const elementName, int value);
|
||||
void sendElementValue(const XMLCh* const elementName, const XMLCh* const value);
|
||||
void sendElementValueList(const XMLCh* const elementName, const StringList* const values);
|
||||
|
||||
void sendIndentedElement(const XMLCh* const elementName);
|
||||
void sendIndentedElementWithID(const XMLCh* const elementName, XSObject* obj); //adds the ID to the attribute list before sending
|
||||
void sendUnindentedElement(const XMLCh* const elementName);
|
||||
|
||||
void writeOpen(const XMLCh* const elementName);
|
||||
void writeOpen(const XMLCh* const elementName, const StringList* const attrs);
|
||||
void writeClose(const XMLCh* const elementName);
|
||||
void writeValue(const XMLCh* const elementName, const XMLCh* const value);
|
||||
void writeValue(const XMLCh* const elementName, const StringList* const values);
|
||||
void writeEmpty(const XMLCh* const elementName, const StringList* const attrs);
|
||||
void writeEmpty(const XMLCh* const elementName);
|
||||
void writeString(const XMLCh* const string);
|
||||
|
||||
const XMLCh* translateScope(XSConstants::SCOPE scope);
|
||||
const XMLCh* translateValueConstraint(XSConstants::VALUE_CONSTRAINT constraintKind);
|
||||
const XMLCh* translateBlockOrFinal(short val);
|
||||
const XMLCh* translateDerivationMethod(XSConstants::DERIVATION_TYPE derivation);
|
||||
const XMLCh* translateProcessContents(XSWildcard::PROCESS_CONTENTS processContents);
|
||||
const XMLCh* translateCompositor(XSModelGroup::COMPOSITOR_TYPE compositor);
|
||||
const XMLCh* translateValidity(PSVIItem::VALIDITY_STATE validity);
|
||||
const XMLCh* translateValidationAttempted(PSVIItem::ASSESSMENT_TYPE validation);
|
||||
const XMLCh* translateIdConstraintCategory(XSIDCDefinition::IC_CATEGORY category);
|
||||
const XMLCh* translateComplexContentType(XSComplexTypeDefinition::CONTENT_TYPE contentType);
|
||||
const XMLCh* translateSimpleTypeVariety(XSSimpleTypeDefinition::VARIETY variety);
|
||||
const XMLCh* translateOrderedFacet(XSSimpleTypeDefinition::ORDERING ordered);
|
||||
const XMLCh* translateFacet(XSSimpleTypeDefinition::FACET facetKind);
|
||||
const XMLCh* translateComponentType(XSConstants::COMPONENT_TYPE type);
|
||||
const XMLCh* translateBool(bool flag);
|
||||
|
||||
XMLCh* createID(XSObject* obj);
|
||||
const XMLCh* getIdName(XSObject* obj);
|
||||
void incIndent();
|
||||
void decIndent();
|
||||
|
||||
protected:
|
||||
XMLFormatter* fFormatter;
|
||||
XMLFormatter* fErrorFormatter;
|
||||
|
||||
StringList* fAttrList;
|
||||
XMLCh* fTempResult;
|
||||
XMLCh* fIndentChars;
|
||||
XMLCh* fBaseUri;
|
||||
|
||||
unsigned int fIndent;
|
||||
unsigned int fIndentCap;
|
||||
unsigned int fAnonNum;
|
||||
|
||||
RefHashTableOf<XMLCh>* fIdMap;
|
||||
RefVectorOf<XSObject>* fDefinedIds;
|
||||
RefArrayVectorOf<XMLCh>* fIdNames;
|
||||
RefArrayVectorOf<XMLCh>* fObjectLocations;
|
||||
|
||||
RefHashTableOf<XMLCh>* fPrefixMap;
|
||||
RefArrayVectorOf<XMLCh>* fNamespaces;
|
||||
|
||||
ValueVectorOf<XMLSize_t>* fNSAttributes; //REVISIT dont need if NSAttrs in different object
|
||||
ValueStackOf<bool>* fElementChildren;
|
||||
|
||||
RefVectorOf<AttrInfo>* fAttributesInfo;
|
||||
};
|
||||
|
||||
class PSVIAdvancedHandler: public XMLDocumentHandler {
|
||||
public:
|
||||
PSVIAdvancedHandler(PSVIWriterHandlers* writerHandler) : XMLDocumentHandler(), fWriterHandler(writerHandler) {}
|
||||
~PSVIAdvancedHandler() {}
|
||||
void docCharacters(const XMLCh* const, const XMLSize_t, const bool) {}
|
||||
void docComment(const XMLCh* const) {}
|
||||
void docPI(const XMLCh* const, const XMLCh* const) {}
|
||||
void endDocument() {}
|
||||
void endElement(const XMLElementDecl&, const unsigned int, const bool, const XMLCh* const) {}
|
||||
void endEntityReference(const XMLEntityDecl&) {}
|
||||
|
||||
void ignorableWhitespace(const XMLCh* const, const XMLSize_t, const bool) {}
|
||||
|
||||
void resetDocument() {}
|
||||
void startDocument() {}
|
||||
void startElement(const XMLElementDecl&, const unsigned int, const XMLCh* const, const RefVectorOf<XMLAttr>&
|
||||
,const XMLSize_t, const bool, const bool) {}
|
||||
void startEntityReference(const XMLEntityDecl&) {};
|
||||
|
||||
void XMLDecl(const XMLCh* const versionStr, const XMLCh* const encodingStr, const XMLCh* const standaloneStr, const XMLCh* const autoEncodingStr);
|
||||
private:
|
||||
PSVIWriterHandlers* fWriterHandler;
|
||||
};
|
||||
|
||||
#endif
|
||||
Executable
+164
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* This simplistic sample illustrates how an XML application can use
|
||||
* the SAX entityResolver handler to provide customized handling for
|
||||
* external entities.
|
||||
*
|
||||
* It registers an entity resolver with the parser. When ever the parser
|
||||
* comes across an external entity, like a reference to an external DTD
|
||||
* file, it calls the 'resolveEntity()' callback. This callback in this
|
||||
* sample checks to see if the external entity to be resolved is the file
|
||||
* 'personal.dtd'.
|
||||
*
|
||||
* If it is then, it redirects the input stream to the file 'redirect.dtd',
|
||||
* which is then read instead of 'personal.dtd'.
|
||||
*
|
||||
* If the external entity to be resolved was not the file 'personal.dtd', the
|
||||
* callback returns NULL indicating that do the default behaviour which is
|
||||
* to read the contents of 'personal.dtd'.
|
||||
*
|
||||
* $Id: Redirect.cpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/parsers/SAXParser.hpp>
|
||||
#include "Redirect.hpp"
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void usage()
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
||||
" Redirect <XML file>\n\n"
|
||||
"This program installs an entity resolver, traps the call to\n"
|
||||
"the external DTD file and redirects it to another application\n"
|
||||
"specific file which contains the actual dtd.\n\n"
|
||||
"The program then counts and reports the number of elements and\n"
|
||||
"attributes in the given XML file.\n"
|
||||
<< XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Program entry point
|
||||
// ---------------------------------------------------------------------------
|
||||
int main(int argc, char* args[])
|
||||
{
|
||||
// Initialize the XML4C system
|
||||
try
|
||||
{
|
||||
XMLPlatformUtils::Initialize();
|
||||
}
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
|
||||
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// We only have one parameter, which is the file to process
|
||||
// We only have one required parameter, which is the file to process
|
||||
if ((argc != 2) || (*(args[1]) == '-'))
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* xmlFile = args[1];
|
||||
|
||||
//
|
||||
// Create a SAX parser object. Then, according to what we were told on
|
||||
// the command line, set it to validate or not.
|
||||
//
|
||||
SAXParser* parser = new SAXParser;
|
||||
|
||||
//
|
||||
// Create our SAX handler object and install it on the parser, as the
|
||||
// document, entity and error handlers.
|
||||
//
|
||||
RedirectHandlers handler;
|
||||
parser->setDocumentHandler(&handler);
|
||||
parser->setErrorHandler(&handler);
|
||||
//Use the new XML Entity Resolver
|
||||
//parser->setEntityResolver(&handler);
|
||||
parser->setXMLEntityResolver(&handler);
|
||||
|
||||
//
|
||||
// Get the starting time and kick off the parse of the indicated file.
|
||||
// Catch any exceptions that might propogate out of it.
|
||||
//
|
||||
unsigned long duration;
|
||||
int errorCount = 0;
|
||||
int errorCode = 0;
|
||||
try
|
||||
{
|
||||
const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
|
||||
parser->parse(xmlFile);
|
||||
const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
|
||||
duration = endMillis - startMillis;
|
||||
errorCount = parser->getErrorCount();
|
||||
}
|
||||
catch (const OutOfMemoryException&)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 5;
|
||||
}
|
||||
catch (const XMLException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << xmlFile << "'\n"
|
||||
<< "Exception message is: \n"
|
||||
<< StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 4;
|
||||
}
|
||||
|
||||
if(errorCode) {
|
||||
XMLPlatformUtils::Terminate();
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
// Print out the stats that we collected and time taken.
|
||||
if (!errorCount) {
|
||||
XERCES_STD_QUALIFIER cout << xmlFile << ": " << duration << " ms ("
|
||||
<< handler.getElementCount() << " elems, "
|
||||
<< handler.getAttrCount() << " attrs, "
|
||||
<< handler.getSpaceCount() << " spaces, "
|
||||
<< handler.getCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
//
|
||||
// Delete the parser itself. Must be done prior to calling Terminate, below.
|
||||
//
|
||||
delete parser;
|
||||
|
||||
XMLPlatformUtils::Terminate();
|
||||
|
||||
if (errorCount > 0)
|
||||
return 4;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: Redirect.hpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes for all the program files to see
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include "RedirectHandlers.hpp"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple class that lets us do easy (though not terribly efficient)
|
||||
// trancoding of XMLCh data to local code page for display.
|
||||
// ---------------------------------------------------------------------------
|
||||
class StrX
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StrX(const XMLCh* const toTranscode)
|
||||
{
|
||||
// Call the private transcoding method
|
||||
fLocalForm = XMLString::transcode(toTranscode);
|
||||
}
|
||||
|
||||
~StrX()
|
||||
{
|
||||
XMLString::release(&fLocalForm);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
const char* localForm() const
|
||||
{
|
||||
return fLocalForm;
|
||||
}
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fLocalForm
|
||||
// This is the local code page form of the string.
|
||||
// -----------------------------------------------------------------------
|
||||
char* fLocalForm;
|
||||
};
|
||||
|
||||
inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
||||
{
|
||||
target << toDump.localForm();
|
||||
return target;
|
||||
}
|
||||
Executable
+167
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: RedirectHandlers.cpp 673248 2008-07-02 00:58:08Z dbertoni $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/XMLUniDefs.hpp>
|
||||
#include <xercesc/util/XMLUni.hpp>
|
||||
#include <xercesc/sax/AttributeList.hpp>
|
||||
#include <xercesc/sax/SAXParseException.hpp>
|
||||
#include <xercesc/sax/SAXException.hpp>
|
||||
#include <xercesc/framework/LocalFileInputSource.hpp>
|
||||
#include "Redirect.hpp"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local constant data
|
||||
//
|
||||
// gFileToTrap
|
||||
// This is the file that we are looking for in the entity handler, to
|
||||
// redirect to another file.
|
||||
//
|
||||
// gRedirectToFile
|
||||
// This is the file that we are going to redirect the parser to.
|
||||
// ---------------------------------------------------------------------------
|
||||
static const XMLCh gFileToTrap[] =
|
||||
{
|
||||
chLatin_p, chLatin_e, chLatin_r, chLatin_s, chLatin_o, chLatin_n
|
||||
, chLatin_a, chLatin_l, chPeriod, chLatin_d, chLatin_t, chLatin_d, chNull
|
||||
};
|
||||
|
||||
static const XMLCh gRedirectToFile[] =
|
||||
{
|
||||
chLatin_r, chLatin_e, chLatin_d, chLatin_i, chLatin_r, chLatin_e
|
||||
, chLatin_c, chLatin_t, chPeriod, chLatin_d, chLatin_t, chLatin_d, chNull
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RedirectHandlers: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
RedirectHandlers::RedirectHandlers() :
|
||||
|
||||
fAttrCount(0)
|
||||
, fCharacterCount(0)
|
||||
, fElementCount(0)
|
||||
, fSpaceCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
RedirectHandlers::~RedirectHandlers()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RedirectHandlers: Implementation of the SAX DocumentHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void RedirectHandlers::startElement(const XMLCh* const /* name */
|
||||
, AttributeList& attributes)
|
||||
{
|
||||
fElementCount++;
|
||||
fAttrCount += attributes.getLength();
|
||||
}
|
||||
|
||||
void RedirectHandlers::characters( const XMLCh* const /* chars */
|
||||
, const XMLSize_t length)
|
||||
{
|
||||
fCharacterCount += length;
|
||||
}
|
||||
|
||||
void RedirectHandlers::ignorableWhitespace( const XMLCh* const /* chars */
|
||||
, const XMLSize_t length)
|
||||
{
|
||||
fSpaceCount += length;
|
||||
}
|
||||
|
||||
void RedirectHandlers::resetDocument()
|
||||
{
|
||||
fAttrCount = 0;
|
||||
fCharacterCount = 0;
|
||||
fElementCount = 0;
|
||||
fSpaceCount = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RedirectHandlers: Overrides of the SAX ErrorHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void RedirectHandlers::error(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError at (file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void RedirectHandlers::fatalError(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nFatal Error at (file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void RedirectHandlers::warning(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nWarning at (file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
|
||||
// This is the SAX2 resolveEntity interface...
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the SAX EntityResolver interface
|
||||
// -----------------------------------------------------------------------
|
||||
InputSource* RedirectHandlers::resolveEntity(const XMLCh* const /* publicId */
|
||||
, const XMLCh* const systemId)
|
||||
{
|
||||
//
|
||||
// If it's our file, then create a new URL input source for the file that
|
||||
// we want to really be used. Otherwise, just return NULL to let the
|
||||
// default action occur.
|
||||
if (XMLString::compareString(gFileToTrap, systemId) != 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
// They were equal, so redirect to our other file
|
||||
return new LocalFileInputSource(gRedirectToFile);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the XMLEntityResolver interface
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
InputSource* RedirectHandlers::resolveEntity(XMLResourceIdentifier* resourceIdentifier)
|
||||
{
|
||||
// Call the SAX2 version.
|
||||
return resolveEntity(NULL, resourceIdentifier->getSystemId());
|
||||
}
|
||||
Executable
+121
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: RedirectHandlers.hpp 679377 2008-07-24 11:56:42Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/sax/HandlerBase.hpp>
|
||||
#include <xercesc/util/XMLEntityResolver.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
class AttributeList;
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
|
||||
class RedirectHandlers : public HandlerBase, public XMLEntityResolver
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
RedirectHandlers();
|
||||
~RedirectHandlers();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t getElementCount()
|
||||
{
|
||||
return fElementCount;
|
||||
}
|
||||
|
||||
XMLSize_t getAttrCount()
|
||||
{
|
||||
return fAttrCount;
|
||||
}
|
||||
|
||||
XMLSize_t getCharacterCount()
|
||||
{
|
||||
return fCharacterCount;
|
||||
}
|
||||
|
||||
XMLSize_t getSpaceCount()
|
||||
{
|
||||
return fSpaceCount;
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the SAX DocumentHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void startElement(const XMLCh* const name, AttributeList& attributes);
|
||||
void characters(const XMLCh* const chars, const XMLSize_t length);
|
||||
void ignorableWhitespace(const XMLCh* const chars, const XMLSize_t length);
|
||||
void resetDocument();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the SAX ErrorHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void warning(const SAXParseException& exc);
|
||||
void error(const SAXParseException& exc);
|
||||
void fatalError(const SAXParseException& exc);
|
||||
|
||||
|
||||
// This is the SAX2 resolveEntity interface. This is inherited from
|
||||
// EntityResolver.
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the SAX EntityResolver interface
|
||||
// -----------------------------------------------------------------------
|
||||
InputSource* resolveEntity
|
||||
(
|
||||
const XMLCh* const publicId
|
||||
, const XMLCh* const systemId
|
||||
);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the XMLEntityResolver interface
|
||||
// -----------------------------------------------------------------------
|
||||
InputSource* resolveEntity
|
||||
(
|
||||
XMLResourceIdentifier* resourceIdentifier
|
||||
);
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fAttrCount
|
||||
// fCharacterCount
|
||||
// fElementCount
|
||||
// fSpaceCount
|
||||
// These are just counters that are run upwards based on the input
|
||||
// from the document handlers.
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t fAttrCount;
|
||||
XMLSize_t fCharacterCount;
|
||||
XMLSize_t fElementCount;
|
||||
XMLSize_t fSpaceCount;
|
||||
};
|
||||
Executable
+346
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAX2Count.cpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include "SAX2Count.hpp"
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/sax2/SAX2XMLReader.hpp>
|
||||
#include <xercesc/sax2/XMLReaderFactory.hpp>
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <fstream>
|
||||
#else
|
||||
#include <fstream.h>
|
||||
#endif
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void usage()
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
||||
" SAX2Count [options] <XML file | List file>\n\n"
|
||||
"This program invokes the SAX2XMLReader, and then prints the\n"
|
||||
"number of elements, attributes, spaces and characters found\n"
|
||||
"in each XML file, using SAX2 API.\n\n"
|
||||
"Options:\n"
|
||||
" -l Indicate the input file is a List File that has a list of xml files.\n"
|
||||
" Default to off (Input file is an XML file).\n"
|
||||
" -v=xxx Validation scheme [always | never | auto*].\n"
|
||||
" -f Enable full schema constraint checking processing. Defaults to off.\n"
|
||||
" -p Enable namespace-prefixes feature. Defaults to off.\n"
|
||||
" -n Disable namespace processing. Defaults to on.\n"
|
||||
" NOTE: THIS IS OPPOSITE FROM OTHER SAMPLES.\n"
|
||||
" -s Disable schema processing. Defaults to on.\n"
|
||||
" NOTE: THIS IS OPPOSITE FROM OTHER SAMPLES.\n"
|
||||
" -i Disable identity constraint checking. Defaults to on.\n"
|
||||
" NOTE: THIS IS OPPOSITE FROM OTHER SAMPLES.\n"
|
||||
" -locale=ll_CC specify the locale, default: en_US.\n"
|
||||
" -? Show this help.\n\n"
|
||||
" * = Default if not provided explicitly.\n"
|
||||
<< XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Program entry point
|
||||
// ---------------------------------------------------------------------------
|
||||
int main(int argC, char* argV[])
|
||||
{
|
||||
|
||||
// Check command line and extract arguments.
|
||||
if (argC < 2)
|
||||
{
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* xmlFile = 0;
|
||||
SAX2XMLReader::ValSchemes valScheme = SAX2XMLReader::Val_Auto;
|
||||
bool doNamespaces = true;
|
||||
bool doSchema = true;
|
||||
bool schemaFullChecking = false;
|
||||
bool identityConstraintChecking = true;
|
||||
bool doList = false;
|
||||
bool errorOccurred = false;
|
||||
bool namespacePrefixes = false;
|
||||
bool recognizeNEL = false;
|
||||
char localeStr[64];
|
||||
memset(localeStr, 0, sizeof localeStr);
|
||||
|
||||
int argInd;
|
||||
for (argInd = 1; argInd < argC; argInd++)
|
||||
{
|
||||
// Break out on first parm not starting with a dash
|
||||
if (argV[argInd][0] != '-')
|
||||
break;
|
||||
|
||||
// Watch for special case help request
|
||||
if (!strcmp(argV[argInd], "-?"))
|
||||
{
|
||||
usage();
|
||||
return 2;
|
||||
}
|
||||
else if (!strncmp(argV[argInd], "-v=", 3)
|
||||
|| !strncmp(argV[argInd], "-V=", 3))
|
||||
{
|
||||
const char* const parm = &argV[argInd][3];
|
||||
|
||||
if (!strcmp(parm, "never"))
|
||||
valScheme = SAX2XMLReader::Val_Never;
|
||||
else if (!strcmp(parm, "auto"))
|
||||
valScheme = SAX2XMLReader::Val_Auto;
|
||||
else if (!strcmp(parm, "always"))
|
||||
valScheme = SAX2XMLReader::Val_Always;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -v= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-n")
|
||||
|| !strcmp(argV[argInd], "-N"))
|
||||
{
|
||||
doNamespaces = false;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-s")
|
||||
|| !strcmp(argV[argInd], "-S"))
|
||||
{
|
||||
doSchema = false;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-f")
|
||||
|| !strcmp(argV[argInd], "-F"))
|
||||
{
|
||||
schemaFullChecking = true;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-i")
|
||||
|| !strcmp(argV[argInd], "-I"))
|
||||
{
|
||||
identityConstraintChecking = false;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-l")
|
||||
|| !strcmp(argV[argInd], "-L"))
|
||||
{
|
||||
doList = true;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-p")
|
||||
|| !strcmp(argV[argInd], "-P"))
|
||||
{
|
||||
namespacePrefixes = true;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-special:nel"))
|
||||
{
|
||||
// turning this on will lead to non-standard compliance behaviour
|
||||
// it will recognize the unicode character 0x85 as new line character
|
||||
// instead of regular character as specified in XML 1.0
|
||||
// do not turn this on unless really necessary
|
||||
recognizeNEL = true;
|
||||
}
|
||||
else if (!strncmp(argV[argInd], "-locale=", 8))
|
||||
{
|
||||
// Get out the end of line
|
||||
strncpy(localeStr, &(argV[argInd][8]), sizeof localeStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[argInd]
|
||||
<< "', ignoring it\n" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// There should be only one and only one parameter left, and that
|
||||
// should be the file name.
|
||||
//
|
||||
if (argInd != argC - 1)
|
||||
{
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Initialize the XML4C2 system
|
||||
try
|
||||
{
|
||||
if (strlen(localeStr))
|
||||
{
|
||||
XMLPlatformUtils::Initialize(localeStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
XMLPlatformUtils::Initialize();
|
||||
}
|
||||
|
||||
if (recognizeNEL)
|
||||
{
|
||||
XMLPlatformUtils::recognizeNEL(recognizeNEL);
|
||||
}
|
||||
}
|
||||
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
|
||||
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Create a SAX parser object. Then, according to what we were told on
|
||||
// the command line, set it to validate or not.
|
||||
//
|
||||
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
|
||||
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, doNamespaces);
|
||||
parser->setFeature(XMLUni::fgXercesSchema, doSchema);
|
||||
parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
|
||||
parser->setFeature(XMLUni::fgXercesIdentityConstraintChecking, identityConstraintChecking);
|
||||
parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, namespacePrefixes);
|
||||
|
||||
if (valScheme == SAX2XMLReader::Val_Auto)
|
||||
{
|
||||
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
|
||||
parser->setFeature(XMLUni::fgXercesDynamic, true);
|
||||
}
|
||||
if (valScheme == SAX2XMLReader::Val_Never)
|
||||
{
|
||||
parser->setFeature(XMLUni::fgSAX2CoreValidation, false);
|
||||
}
|
||||
if (valScheme == SAX2XMLReader::Val_Always)
|
||||
{
|
||||
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
|
||||
parser->setFeature(XMLUni::fgXercesDynamic, false);
|
||||
}
|
||||
|
||||
//
|
||||
// Create our SAX handler object and install it on the parser, as the
|
||||
// document and error handler.
|
||||
//
|
||||
SAX2CountHandlers handler;
|
||||
parser->setContentHandler(&handler);
|
||||
parser->setErrorHandler(&handler);
|
||||
|
||||
//
|
||||
// Get the starting time and kick off the parse of the indicated
|
||||
// file. Catch any exceptions that might propogate out of it.
|
||||
//
|
||||
unsigned long duration;
|
||||
|
||||
bool more = true;
|
||||
XERCES_STD_QUALIFIER ifstream fin;
|
||||
|
||||
// the input is a list file
|
||||
if (doList)
|
||||
fin.open(argV[argInd]);
|
||||
|
||||
if (fin.fail()) {
|
||||
XERCES_STD_QUALIFIER cerr <<"Cannot open the list file: " << argV[argInd] << XERCES_STD_QUALIFIER endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
while (more)
|
||||
{
|
||||
char fURI[1000];
|
||||
//initialize the array to zeros
|
||||
memset(fURI,0,sizeof(fURI));
|
||||
|
||||
if (doList) {
|
||||
if (! fin.eof() ) {
|
||||
fin.getline (fURI, sizeof(fURI));
|
||||
if (!*fURI)
|
||||
continue;
|
||||
else {
|
||||
xmlFile = fURI;
|
||||
XERCES_STD_QUALIFIER cerr << "==Parsing== " << xmlFile << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
else {
|
||||
xmlFile = argV[argInd];
|
||||
more = false;
|
||||
}
|
||||
|
||||
//reset error count first
|
||||
handler.resetErrors();
|
||||
|
||||
try
|
||||
{
|
||||
const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
|
||||
parser->parse(xmlFile);
|
||||
const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
|
||||
duration = endMillis - startMillis;
|
||||
}
|
||||
catch (const OutOfMemoryException&)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
|
||||
errorOccurred = true;
|
||||
continue;
|
||||
}
|
||||
catch (const XMLException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << xmlFile << "'\n"
|
||||
<< "Exception message is: \n"
|
||||
<< StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
|
||||
errorOccurred = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
catch (...)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nUnexpected exception during parsing: '" << xmlFile << "'\n";
|
||||
errorOccurred = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Print out the stats that we collected and time taken
|
||||
if (!handler.getSawErrors())
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << xmlFile << ": " << duration << " ms ("
|
||||
<< handler.getElementCount() << " elems, "
|
||||
<< handler.getAttrCount() << " attrs, "
|
||||
<< handler.getSpaceCount() << " spaces, "
|
||||
<< handler.getCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
else
|
||||
errorOccurred = true;
|
||||
}
|
||||
|
||||
if (doList)
|
||||
fin.close();
|
||||
|
||||
//
|
||||
// Delete the parser itself. Must be done prior to calling Terminate, below.
|
||||
//
|
||||
delete parser;
|
||||
|
||||
// And call the termination method
|
||||
XMLPlatformUtils::Terminate();
|
||||
|
||||
if (errorOccurred)
|
||||
return 4;
|
||||
else
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
Executable
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAX2Count.hpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes for all the program files to see
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
#include "SAX2CountHandlers.hpp"
|
||||
#include <xercesc/sax2/XMLReaderFactory.hpp>
|
||||
#include <xercesc/sax2/SAX2XMLReader.hpp>
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple class that lets us do easy (though not terribly efficient)
|
||||
// trancoding of XMLCh data to local code page for display.
|
||||
// ---------------------------------------------------------------------------
|
||||
class StrX
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StrX(const XMLCh* const toTranscode)
|
||||
{
|
||||
// Call the private transcoding method
|
||||
fLocalForm = XMLString::transcode(toTranscode);
|
||||
}
|
||||
|
||||
~StrX()
|
||||
{
|
||||
XMLString::release(&fLocalForm);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
const char* localForm() const
|
||||
{
|
||||
return fLocalForm;
|
||||
}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fLocalForm
|
||||
// This is the local code page form of the string.
|
||||
// -----------------------------------------------------------------------
|
||||
char* fLocalForm;
|
||||
};
|
||||
|
||||
inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
||||
{
|
||||
target << toDump.localForm();
|
||||
return target;
|
||||
}
|
||||
Executable
+114
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAX2CountHandlers.cpp 557282 2007-07-18 14:54:15Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include "SAX2Count.hpp"
|
||||
#include <xercesc/sax2/Attributes.hpp>
|
||||
#include <xercesc/sax/SAXParseException.hpp>
|
||||
#include <xercesc/sax/SAXException.hpp>
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAX2CountHandlers: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
SAX2CountHandlers::SAX2CountHandlers() :
|
||||
|
||||
fAttrCount(0)
|
||||
, fCharacterCount(0)
|
||||
, fElementCount(0)
|
||||
, fSpaceCount(0)
|
||||
, fSawErrors(false)
|
||||
{
|
||||
}
|
||||
|
||||
SAX2CountHandlers::~SAX2CountHandlers()
|
||||
{
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAX2CountHandlers: Implementation of the SAX DocumentHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void SAX2CountHandlers::startElement(const XMLCh* const /* uri */
|
||||
, const XMLCh* const /* localname */
|
||||
, const XMLCh* const /* qname */
|
||||
, const Attributes& attrs)
|
||||
{
|
||||
fElementCount++;
|
||||
fAttrCount += attrs.getLength();
|
||||
}
|
||||
|
||||
void SAX2CountHandlers::characters( const XMLCh* const /* chars */
|
||||
, const XMLSize_t length)
|
||||
{
|
||||
fCharacterCount += length;
|
||||
}
|
||||
|
||||
void SAX2CountHandlers::ignorableWhitespace( const XMLCh* const /* chars */
|
||||
, const XMLSize_t length)
|
||||
{
|
||||
fSpaceCount += length;
|
||||
}
|
||||
|
||||
void SAX2CountHandlers::startDocument()
|
||||
{
|
||||
fAttrCount = 0;
|
||||
fCharacterCount = 0;
|
||||
fElementCount = 0;
|
||||
fSpaceCount = 0;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAX2CountHandlers: Overrides of the SAX ErrorHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void SAX2CountHandlers::error(const SAXParseException& e)
|
||||
{
|
||||
fSawErrors = true;
|
||||
XERCES_STD_QUALIFIER cerr << "\nError at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void SAX2CountHandlers::fatalError(const SAXParseException& e)
|
||||
{
|
||||
fSawErrors = true;
|
||||
XERCES_STD_QUALIFIER cerr << "\nFatal Error at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void SAX2CountHandlers::warning(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nWarning at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void SAX2CountHandlers::resetErrors()
|
||||
{
|
||||
fSawErrors = false;
|
||||
}
|
||||
Executable
+108
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAX2CountHandlers.hpp 679377 2008-07-24 11:56:42Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/sax2/Attributes.hpp>
|
||||
#include <xercesc/sax2/DefaultHandler.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
class SAX2CountHandlers : public DefaultHandler
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
SAX2CountHandlers();
|
||||
~SAX2CountHandlers();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t getElementCount() const
|
||||
{
|
||||
return fElementCount;
|
||||
}
|
||||
|
||||
XMLSize_t getAttrCount() const
|
||||
{
|
||||
return fAttrCount;
|
||||
}
|
||||
|
||||
XMLSize_t getCharacterCount() const
|
||||
{
|
||||
return fCharacterCount;
|
||||
}
|
||||
|
||||
bool getSawErrors() const
|
||||
{
|
||||
return fSawErrors;
|
||||
}
|
||||
|
||||
XMLSize_t getSpaceCount() const
|
||||
{
|
||||
return fSpaceCount;
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the SAX ContentHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs);
|
||||
void characters(const XMLCh* const chars, const XMLSize_t length);
|
||||
void ignorableWhitespace(const XMLCh* const chars, const XMLSize_t length);
|
||||
void startDocument();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the SAX ErrorHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void warning(const SAXParseException& exc);
|
||||
void error(const SAXParseException& exc);
|
||||
void fatalError(const SAXParseException& exc);
|
||||
void resetErrors();
|
||||
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fAttrCount
|
||||
// fCharacterCount
|
||||
// fElementCount
|
||||
// fSpaceCount
|
||||
// These are just counters that are run upwards based on the input
|
||||
// from the document handlers.
|
||||
//
|
||||
// fSawErrors
|
||||
// This is set by the error handlers, and is queryable later to
|
||||
// see if any errors occured.
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t fAttrCount;
|
||||
XMLSize_t fCharacterCount;
|
||||
XMLSize_t fElementCount;
|
||||
XMLSize_t fSpaceCount;
|
||||
bool fSawErrors;
|
||||
};
|
||||
Executable
+174
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAX2FilterHandlers.cpp 672311 2008-06-27 16:05:01Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include "SAX2FilterHandlers.hpp"
|
||||
#include <xercesc/sax2/Attributes.hpp>
|
||||
|
||||
struct Attr
|
||||
{
|
||||
const XMLCh* qName;
|
||||
const XMLCh* uri;
|
||||
const XMLCh* localPart;
|
||||
const XMLCh* value;
|
||||
const XMLCh* attrType;
|
||||
};
|
||||
|
||||
class AttrList : public Attributes, public RefVectorOf<Attr>
|
||||
{
|
||||
public:
|
||||
AttrList(XMLSize_t count) : RefVectorOf<Attr>(count) {}
|
||||
|
||||
virtual XMLSize_t getLength() const
|
||||
{
|
||||
return size();
|
||||
}
|
||||
|
||||
virtual const XMLCh* getURI(const XMLSize_t index) const
|
||||
{
|
||||
return elementAt(index)->uri;
|
||||
}
|
||||
virtual const XMLCh* getLocalName(const XMLSize_t index) const
|
||||
{
|
||||
return elementAt(index)->localPart;
|
||||
}
|
||||
virtual const XMLCh* getQName(const XMLSize_t index) const
|
||||
{
|
||||
return elementAt(index)->qName;
|
||||
}
|
||||
virtual const XMLCh* getType(const XMLSize_t index) const
|
||||
{
|
||||
return elementAt(index)->attrType;
|
||||
}
|
||||
virtual const XMLCh* getValue(const XMLSize_t index) const
|
||||
{
|
||||
return elementAt(index)->value;
|
||||
}
|
||||
|
||||
|
||||
virtual bool getIndex(const XMLCh* const uri,
|
||||
const XMLCh* const localPart,
|
||||
XMLSize_t& i) const
|
||||
{
|
||||
for(i=0;i<size();i++)
|
||||
if(XMLString::equals(elementAt(i)->uri,uri) && XMLString::equals(elementAt(i)->localPart,localPart))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual int getIndex(const XMLCh* const uri, const XMLCh* const localPart ) const
|
||||
{
|
||||
for(XMLSize_t i=0;i<size();i++)
|
||||
if(XMLString::equals(elementAt(i)->uri,uri) && XMLString::equals(elementAt(i)->localPart,localPart))
|
||||
return (int)i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
virtual bool getIndex(const XMLCh* const qName, XMLSize_t& i) const
|
||||
{
|
||||
for(i=0;i<size();i++)
|
||||
if(XMLString::equals(elementAt(i)->qName,qName))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual int getIndex(const XMLCh* const qName ) const
|
||||
{
|
||||
for(XMLSize_t i=0;i<size();i++)
|
||||
if(XMLString::equals(elementAt(i)->qName,qName))
|
||||
return (int)i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
virtual const XMLCh* getType(const XMLCh* const uri, const XMLCh* const localPart ) const
|
||||
{
|
||||
for(XMLSize_t i=0;i<size();i++)
|
||||
if(XMLString::equals(elementAt(i)->uri,uri) && XMLString::equals(elementAt(i)->localPart,localPart))
|
||||
return elementAt(i)->attrType;
|
||||
return NULL;
|
||||
}
|
||||
virtual const XMLCh* getType(const XMLCh* const qName) const
|
||||
{
|
||||
for(XMLSize_t i=0;i<size();i++)
|
||||
if(XMLString::equals(elementAt(i)->qName,qName))
|
||||
return elementAt(i)->attrType;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual const XMLCh* getValue(const XMLCh* const uri, const XMLCh* const localPart ) const
|
||||
{
|
||||
for(XMLSize_t i=0;i<size();i++)
|
||||
if(XMLString::equals(elementAt(i)->uri,uri) && XMLString::equals(elementAt(i)->localPart,localPart))
|
||||
return elementAt(i)->value;
|
||||
return NULL;
|
||||
}
|
||||
virtual const XMLCh* getValue(const XMLCh* const qName) const
|
||||
{
|
||||
for(XMLSize_t i=0;i<size();i++)
|
||||
if(XMLString::equals(elementAt(i)->qName,qName))
|
||||
return elementAt(i)->value;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAX2SortAttributesFilter: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
SAX2SortAttributesFilter::SAX2SortAttributesFilter(SAX2XMLReader* parent) : SAX2XMLFilterImpl(parent)
|
||||
{
|
||||
}
|
||||
|
||||
SAX2SortAttributesFilter::~SAX2SortAttributesFilter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAX2SortAttributesFilter: Overrides of the SAX2XMLFilter interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void SAX2SortAttributesFilter::startElement(const XMLCh* const uri,
|
||||
const XMLCh* const localname,
|
||||
const XMLCh* const qname,
|
||||
const Attributes& attributes)
|
||||
{
|
||||
AttrList sortedList(attributes.getLength());
|
||||
for(XMLSize_t i=0;i<attributes.getLength();i++)
|
||||
{
|
||||
XMLSize_t j;
|
||||
for(j=0;j<sortedList.getLength();j++)
|
||||
{
|
||||
if(XMLString::compareString(sortedList.elementAt(j)->qName,attributes.getQName(i))>=0)
|
||||
break;
|
||||
}
|
||||
Attr* pClone=new Attr;
|
||||
pClone->qName = attributes.getQName(i);
|
||||
pClone->uri = attributes.getURI(i);
|
||||
pClone->localPart = attributes.getLocalName(i);
|
||||
pClone->value = attributes.getValue(i);
|
||||
pClone->attrType = attributes.getType(i);
|
||||
sortedList.insertElementAt(pClone, j);
|
||||
}
|
||||
SAX2XMLFilterImpl::startElement(uri, localname, qname, sortedList);
|
||||
}
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAX2FilterHandlers.hpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
#include <xercesc/parsers/SAX2XMLFilterImpl.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
class SAX2SortAttributesFilter : public SAX2XMLFilterImpl
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors
|
||||
// -----------------------------------------------------------------------
|
||||
SAX2SortAttributesFilter(SAX2XMLReader* parent);
|
||||
~SAX2SortAttributesFilter();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementations of the SAX2XMLFilter interface
|
||||
// -----------------------------------------------------------------------
|
||||
void startElement( const XMLCh* const uri,
|
||||
const XMLCh* const localname,
|
||||
const XMLCh* const qname,
|
||||
const Attributes& attributes);
|
||||
};
|
||||
|
||||
Executable
+316
@@ -0,0 +1,316 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAX2Print.cpp 677441 2008-07-16 21:55:19Z dbertoni $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/TransService.hpp>
|
||||
#include <xercesc/sax2/SAX2XMLReader.hpp>
|
||||
#include <xercesc/sax2/XMLReaderFactory.hpp>
|
||||
#include "SAX2Print.hpp"
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
#include "SAX2FilterHandlers.hpp"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local data
|
||||
//
|
||||
// encodingName
|
||||
// The encoding we are to output in. If not set on the command line,
|
||||
// then it is defaulted to LATIN1.
|
||||
//
|
||||
// xmlFile
|
||||
// The path to the file to parser. Set via command line.
|
||||
//
|
||||
// valScheme
|
||||
// Indicates what validation scheme to use. It defaults to 'auto', but
|
||||
// can be set via the -v= command.
|
||||
//
|
||||
// expandNamespaces
|
||||
// Indicates if the output should expand the namespaces Alias with
|
||||
// their URI's, defaults to false, can be set via the command line -e
|
||||
// ---------------------------------------------------------------------------
|
||||
static const char* encodingName = "LATIN1";
|
||||
static XMLFormatter::UnRepFlags unRepFlags = XMLFormatter::UnRep_CharRef;
|
||||
static char* xmlFile = 0;
|
||||
static SAX2XMLReader::ValSchemes valScheme = SAX2XMLReader::Val_Auto;
|
||||
static bool expandNamespaces= false ;
|
||||
static bool doNamespaces = true;
|
||||
static bool doSchema = true;
|
||||
static bool schemaFullChecking = false;
|
||||
static bool namespacePrefixes = false;
|
||||
static bool sortAttributes = false;
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
static void usage()
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
||||
" SAX2Print [options] <XML file>\n\n"
|
||||
"This program invokes the SAX2XMLReader, and then prints the\n"
|
||||
"data returned by the various SAX2 handlers for the specified\n"
|
||||
"XML file.\n\n"
|
||||
"Options:\n"
|
||||
" -u=xxx Handle unrepresentable chars [fail | rep | ref*].\n"
|
||||
" -v=xxx Validation scheme [always | never | auto*].\n"
|
||||
" -e Expand Namespace Alias with URI's. Defaults to off.\n"
|
||||
" -x=XXX Use a particular encoding for output (LATIN1*).\n"
|
||||
" -f Enable full schema constraint checking processing. Defaults to off.\n"
|
||||
" -p Enable namespace-prefixes feature. Defaults to off.\n"
|
||||
" -n Disable namespace processing. Defaults to on.\n"
|
||||
" NOTE: THIS IS OPPOSITE FROM OTHER SAMPLES.\n"
|
||||
" -s Disable schema processing. Defaults to on.\n"
|
||||
" NOTE: THIS IS OPPOSITE FROM OTHER SAMPLES.\n"
|
||||
" -sa Print the attributes in alphabetic order. Defaults to off.\n"
|
||||
" -? Show this help.\n\n"
|
||||
" * = Default if not provided explicitly.\n\n"
|
||||
"The parser has intrinsic support for the following encodings:\n"
|
||||
" UTF-8, USASCII, ISO8859-1, UTF-16[BL]E, UCS-4[BL]E,\n"
|
||||
" WINDOWS-1252, IBM1140, IBM037, IBM1047.\n"
|
||||
<< XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Program entry point
|
||||
// ---------------------------------------------------------------------------
|
||||
int main(int argC, char* argV[])
|
||||
{
|
||||
// Initialize the XML4C2 system
|
||||
try
|
||||
{
|
||||
XMLPlatformUtils::Initialize();
|
||||
}
|
||||
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Error during initialization! :\n"
|
||||
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check command line and extract arguments.
|
||||
if (argC < 2)
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int parmInd;
|
||||
for (parmInd = 1; parmInd < argC; parmInd++)
|
||||
{
|
||||
// Break out on first parm not starting with a dash
|
||||
if (argV[parmInd][0] != '-')
|
||||
break;
|
||||
|
||||
// Watch for special case help request
|
||||
if (!strcmp(argV[parmInd], "-?"))
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-v=", 3)
|
||||
|| !strncmp(argV[parmInd], "-V=", 3))
|
||||
{
|
||||
const char* const parm = &argV[parmInd][3];
|
||||
|
||||
if (!strcmp(parm, "never"))
|
||||
valScheme = SAX2XMLReader::Val_Never;
|
||||
else if (!strcmp(parm, "auto"))
|
||||
valScheme = SAX2XMLReader::Val_Auto;
|
||||
else if (!strcmp(parm, "always"))
|
||||
valScheme = SAX2XMLReader::Val_Always;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -v= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-e")
|
||||
|| !strcmp(argV[parmInd], "-E"))
|
||||
{
|
||||
expandNamespaces = true;
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-x=", 3)
|
||||
|| !strncmp(argV[parmInd], "-X=", 3))
|
||||
{
|
||||
// Get out the encoding name
|
||||
encodingName = &argV[parmInd][3];
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-u=", 3)
|
||||
|| !strncmp(argV[parmInd], "-U=", 3))
|
||||
{
|
||||
const char* const parm = &argV[parmInd][3];
|
||||
|
||||
if (!strcmp(parm, "fail"))
|
||||
unRepFlags = XMLFormatter::UnRep_Fail;
|
||||
else if (!strcmp(parm, "rep"))
|
||||
unRepFlags = XMLFormatter::UnRep_Replace;
|
||||
else if (!strcmp(parm, "ref"))
|
||||
unRepFlags = XMLFormatter::UnRep_CharRef;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -u= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-n")
|
||||
|| !strcmp(argV[parmInd], "-N"))
|
||||
{
|
||||
doNamespaces = false;
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-s")
|
||||
|| !strcmp(argV[parmInd], "-S"))
|
||||
{
|
||||
doSchema = false;
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-f")
|
||||
|| !strcmp(argV[parmInd], "-F"))
|
||||
{
|
||||
schemaFullChecking = true;
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-p")
|
||||
|| !strcmp(argV[parmInd], "-P"))
|
||||
{
|
||||
namespacePrefixes = true;
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-sa"))
|
||||
{
|
||||
sortAttributes = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[parmInd]
|
||||
<< "', ignoring it\n" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// And now we have to have only one parameter left and it must be
|
||||
// the file name.
|
||||
//
|
||||
if (parmInd + 1 != argC)
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 1;
|
||||
}
|
||||
xmlFile = argV[parmInd];
|
||||
|
||||
//
|
||||
// Create a SAX parser object. Then, according to what we were told on
|
||||
// the command line, set it to validate or not.
|
||||
//
|
||||
SAX2XMLReader* parser;
|
||||
SAX2XMLReader* reader = XMLReaderFactory::createXMLReader();
|
||||
SAX2XMLReader* filter = NULL;
|
||||
if(sortAttributes)
|
||||
{
|
||||
filter=new SAX2SortAttributesFilter(reader);
|
||||
parser=filter;
|
||||
}
|
||||
else
|
||||
parser=reader;
|
||||
|
||||
//
|
||||
// Then, according to what we were told on
|
||||
// the command line, set it to validate or not.
|
||||
//
|
||||
if (valScheme == SAX2XMLReader::Val_Auto)
|
||||
{
|
||||
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
|
||||
parser->setFeature(XMLUni::fgXercesDynamic, true);
|
||||
}
|
||||
|
||||
if (valScheme == SAX2XMLReader::Val_Never)
|
||||
{
|
||||
parser->setFeature(XMLUni::fgSAX2CoreValidation, false);
|
||||
}
|
||||
|
||||
if (valScheme == SAX2XMLReader::Val_Always)
|
||||
{
|
||||
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
|
||||
parser->setFeature(XMLUni::fgXercesDynamic, false);
|
||||
}
|
||||
|
||||
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, doNamespaces);
|
||||
parser->setFeature(XMLUni::fgXercesSchema, doSchema);
|
||||
parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
|
||||
parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, namespacePrefixes);
|
||||
|
||||
//
|
||||
// Create the handler object and install it as the document and error
|
||||
// handler for the parser. Then parse the file and catch any exceptions
|
||||
// that propogate out
|
||||
//
|
||||
|
||||
int errorCount = 0;
|
||||
int errorCode = 0;
|
||||
try
|
||||
{
|
||||
SAX2PrintHandlers handler(encodingName, unRepFlags, expandNamespaces);
|
||||
parser->setContentHandler(&handler);
|
||||
parser->setErrorHandler(&handler);
|
||||
parser->parse(xmlFile);
|
||||
errorCount = parser->getErrorCount();
|
||||
}
|
||||
catch (const OutOfMemoryException&)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 5;
|
||||
}
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nAn error occurred\n Error: "
|
||||
<< StrX(toCatch.getMessage())
|
||||
<< "\n" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 4;
|
||||
}
|
||||
|
||||
if(errorCode) {
|
||||
XMLPlatformUtils::Terminate();
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
//
|
||||
// Delete the parser itself. Must be done prior to calling Terminate, below.
|
||||
//
|
||||
delete reader;
|
||||
if(filter)
|
||||
delete filter;
|
||||
|
||||
// And call the termination method
|
||||
XMLPlatformUtils::Terminate();
|
||||
|
||||
if (errorCount > 0)
|
||||
return 4;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAX2Print.hpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes for all the program files to see
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <string.h>
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include "SAX2PrintHandlers.hpp"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple class that lets us do easy (though not terribly efficient)
|
||||
// trancoding of XMLCh data to local code page for display.
|
||||
// ---------------------------------------------------------------------------
|
||||
class StrX
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StrX(const XMLCh* const toTranscode)
|
||||
{
|
||||
// Call the private transcoding method
|
||||
fLocalForm = XMLString::transcode(toTranscode);
|
||||
}
|
||||
|
||||
~StrX()
|
||||
{
|
||||
XMLString::release(&fLocalForm);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
const char* localForm() const
|
||||
{
|
||||
return fLocalForm;
|
||||
}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fLocalForm
|
||||
// This is the local code page form of the string.
|
||||
// -----------------------------------------------------------------------
|
||||
char* fLocalForm;
|
||||
};
|
||||
|
||||
inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
||||
{
|
||||
target << toDump.localForm();
|
||||
return target;
|
||||
}
|
||||
Executable
+256
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAX2PrintHandlers.cpp 676911 2008-07-15 13:27:32Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/XMLUniDefs.hpp>
|
||||
#include <xercesc/sax2/Attributes.hpp>
|
||||
#include "SAX2Print.hpp"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local const data
|
||||
//
|
||||
// Note: This is the 'safe' way to do these strings. If you compiler supports
|
||||
// L"" style strings, and portability is not a concern, you can use
|
||||
// those types constants directly.
|
||||
// ---------------------------------------------------------------------------
|
||||
static const XMLCh gEndElement[] = { chOpenAngle, chForwardSlash, chNull };
|
||||
static const XMLCh gEndPI[] = { chQuestion, chCloseAngle, chNull };
|
||||
static const XMLCh gStartPI[] = { chOpenAngle, chQuestion, chNull };
|
||||
static const XMLCh gXMLDecl1[] =
|
||||
{
|
||||
chOpenAngle, chQuestion, chLatin_x, chLatin_m, chLatin_l
|
||||
, chSpace, chLatin_v, chLatin_e, chLatin_r, chLatin_s, chLatin_i
|
||||
, chLatin_o, chLatin_n, chEqual, chDoubleQuote, chDigit_1, chPeriod
|
||||
, chDigit_0, chDoubleQuote, chSpace, chLatin_e, chLatin_n, chLatin_c
|
||||
, chLatin_o, chLatin_d, chLatin_i, chLatin_n, chLatin_g, chEqual
|
||||
, chDoubleQuote, chNull
|
||||
};
|
||||
|
||||
static const XMLCh gXMLDecl2[] =
|
||||
{
|
||||
chDoubleQuote, chQuestion, chCloseAngle
|
||||
, chLF, chNull
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAX2PrintHandlers: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
SAX2PrintHandlers::SAX2PrintHandlers( const char* const encodingName
|
||||
, const XMLFormatter::UnRepFlags unRepFlags
|
||||
, const bool expandNamespaces) :
|
||||
|
||||
fFormatter
|
||||
(
|
||||
encodingName
|
||||
, 0
|
||||
, this
|
||||
, XMLFormatter::NoEscapes
|
||||
, unRepFlags
|
||||
),
|
||||
fExpandNS ( expandNamespaces )
|
||||
{
|
||||
//
|
||||
// Go ahead and output an XML Decl with our known encoding. This
|
||||
// is not the best answer, but its the best we can do until we
|
||||
// have SAX2 support.
|
||||
//
|
||||
fFormatter << gXMLDecl1 << fFormatter.getEncodingName() << gXMLDecl2;
|
||||
}
|
||||
|
||||
SAX2PrintHandlers::~SAX2PrintHandlers()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAX2PrintHandlers: Overrides of the output formatter target interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void SAX2PrintHandlers::writeChars(const XMLByte* const /* toWrite */)
|
||||
{
|
||||
}
|
||||
|
||||
void SAX2PrintHandlers::writeChars(const XMLByte* const toWrite,
|
||||
const XMLSize_t count,
|
||||
XMLFormatter* const /* formatter */)
|
||||
{
|
||||
// For this one, just dump them to the standard output
|
||||
// Surprisingly, Solaris was the only platform on which
|
||||
// required the char* cast to print out the string correctly.
|
||||
// Without the cast, it was printing the pointer value in hex.
|
||||
// Quite annoying, considering every other platform printed
|
||||
// the string with the explicit cast to char* below.
|
||||
XERCES_STD_QUALIFIER cout.write((char *) toWrite, (int) count);
|
||||
XERCES_STD_QUALIFIER cout.flush();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAX2PrintHandlers: Overrides of the SAX ErrorHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void SAX2PrintHandlers::error(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void SAX2PrintHandlers::fatalError(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nFatal Error at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void SAX2PrintHandlers::warning(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nWarning at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAX2PrintHandlers: Overrides of the SAX DTDHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void SAX2PrintHandlers::unparsedEntityDecl(const XMLCh* const /* name */
|
||||
, const XMLCh* const /* publicId */
|
||||
, const XMLCh* const /* systemId */
|
||||
, const XMLCh* const /* notationName */)
|
||||
{
|
||||
// Not used at this time
|
||||
}
|
||||
|
||||
|
||||
void SAX2PrintHandlers::notationDecl(const XMLCh* const /* name */
|
||||
, const XMLCh* const /* publicId */
|
||||
, const XMLCh* const /* systemId */)
|
||||
{
|
||||
// Not used at this time
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAX2PrintHandlers: Overrides of the SAX DocumentHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void SAX2PrintHandlers::characters(const XMLCh* const chars
|
||||
, const XMLSize_t length)
|
||||
{
|
||||
fFormatter.formatBuf(chars, length, XMLFormatter::CharEscapes);
|
||||
}
|
||||
|
||||
|
||||
void SAX2PrintHandlers::endDocument()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SAX2PrintHandlers::endElement(const XMLCh* const uri,
|
||||
const XMLCh* const localname,
|
||||
const XMLCh* const qname)
|
||||
{
|
||||
// No escapes are legal here
|
||||
fFormatter << XMLFormatter::NoEscapes << gEndElement ;
|
||||
if ( fExpandNS )
|
||||
{
|
||||
if (XMLString::compareIString(uri,XMLUni::fgZeroLenString) != 0)
|
||||
fFormatter << uri << chColon;
|
||||
fFormatter << localname << chCloseAngle;
|
||||
}
|
||||
else
|
||||
fFormatter << qname << chCloseAngle;
|
||||
}
|
||||
|
||||
|
||||
void SAX2PrintHandlers::ignorableWhitespace( const XMLCh* const chars
|
||||
,const XMLSize_t length)
|
||||
{
|
||||
fFormatter.formatBuf(chars, length, XMLFormatter::NoEscapes);
|
||||
}
|
||||
|
||||
|
||||
void SAX2PrintHandlers::processingInstruction(const XMLCh* const target
|
||||
, const XMLCh* const data)
|
||||
{
|
||||
fFormatter << XMLFormatter::NoEscapes << gStartPI << target;
|
||||
if (data)
|
||||
fFormatter << chSpace << data;
|
||||
fFormatter << XMLFormatter::NoEscapes << gEndPI;
|
||||
}
|
||||
|
||||
|
||||
void SAX2PrintHandlers::startDocument()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SAX2PrintHandlers::startElement(const XMLCh* const uri,
|
||||
const XMLCh* const localname,
|
||||
const XMLCh* const qname,
|
||||
const Attributes& attributes)
|
||||
{
|
||||
// The name has to be representable without any escapes
|
||||
fFormatter << XMLFormatter::NoEscapes << chOpenAngle ;
|
||||
if ( fExpandNS )
|
||||
{
|
||||
if (XMLString::compareIString(uri,XMLUni::fgZeroLenString) != 0)
|
||||
fFormatter << uri << chColon;
|
||||
fFormatter << localname ;
|
||||
}
|
||||
else
|
||||
fFormatter << qname ;
|
||||
|
||||
XMLSize_t len = attributes.getLength();
|
||||
for (XMLSize_t index = 0; index < len; index++)
|
||||
{
|
||||
//
|
||||
// Again the name has to be completely representable. But the
|
||||
// attribute can have refs and requires the attribute style
|
||||
// escaping.
|
||||
//
|
||||
fFormatter << XMLFormatter::NoEscapes << chSpace ;
|
||||
if ( fExpandNS )
|
||||
{
|
||||
if (XMLString::compareIString(attributes.getURI(index),XMLUni::fgZeroLenString) != 0)
|
||||
fFormatter << attributes.getURI(index) << chColon;
|
||||
fFormatter << attributes.getLocalName(index) ;
|
||||
}
|
||||
else
|
||||
fFormatter << attributes.getQName(index) ;
|
||||
|
||||
fFormatter << chEqual << chDoubleQuote
|
||||
<< XMLFormatter::AttrEscapes
|
||||
<< attributes.getValue(index)
|
||||
<< XMLFormatter::NoEscapes
|
||||
<< chDoubleQuote;
|
||||
}
|
||||
fFormatter << chCloseAngle;
|
||||
}
|
||||
Executable
+128
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAX2PrintHandlers.hpp 557282 2007-07-18 14:54:15Z amassari $
|
||||
*/
|
||||
|
||||
#include <xercesc/sax2/DefaultHandler.hpp>
|
||||
#include <xercesc/framework/XMLFormatter.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
class SAX2PrintHandlers : public DefaultHandler, private XMLFormatTarget
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors
|
||||
// -----------------------------------------------------------------------
|
||||
SAX2PrintHandlers
|
||||
(
|
||||
const char* const encodingName
|
||||
, const XMLFormatter::UnRepFlags unRepFlags
|
||||
, const bool expandNamespaces
|
||||
);
|
||||
~SAX2PrintHandlers();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementations of the format target interface
|
||||
// -----------------------------------------------------------------------
|
||||
void writeChars
|
||||
(
|
||||
const XMLByte* const toWrite
|
||||
);
|
||||
|
||||
virtual void writeChars
|
||||
(
|
||||
const XMLByte* const toWrite
|
||||
, const XMLSize_t count
|
||||
, XMLFormatter* const formatter
|
||||
);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementations of the SAX DocumentHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void endDocument();
|
||||
|
||||
void endElement( const XMLCh* const uri,
|
||||
const XMLCh* const localname,
|
||||
const XMLCh* const qname);
|
||||
|
||||
void characters(const XMLCh* const chars, const XMLSize_t length);
|
||||
|
||||
void ignorableWhitespace
|
||||
(
|
||||
const XMLCh* const chars
|
||||
, const XMLSize_t length
|
||||
);
|
||||
|
||||
void processingInstruction
|
||||
(
|
||||
const XMLCh* const target
|
||||
, const XMLCh* const data
|
||||
);
|
||||
|
||||
void startDocument();
|
||||
|
||||
void startElement( const XMLCh* const uri,
|
||||
const XMLCh* const localname,
|
||||
const XMLCh* const qname,
|
||||
const Attributes& attributes);
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementations of the SAX ErrorHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void warning(const SAXParseException& exc);
|
||||
void error(const SAXParseException& exc);
|
||||
void fatalError(const SAXParseException& exc);
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementation of the SAX DTDHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void notationDecl
|
||||
(
|
||||
const XMLCh* const name
|
||||
, const XMLCh* const publicId
|
||||
, const XMLCh* const systemId
|
||||
);
|
||||
|
||||
void unparsedEntityDecl
|
||||
(
|
||||
const XMLCh* const name
|
||||
, const XMLCh* const publicId
|
||||
, const XMLCh* const systemId
|
||||
, const XMLCh* const notationName
|
||||
);
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fFormatter
|
||||
// This is the formatter object that is used to output the data
|
||||
// to the target. It is set up to format to the standard output
|
||||
// stream.
|
||||
// -----------------------------------------------------------------------
|
||||
XMLFormatter fFormatter;
|
||||
bool fExpandNS ;
|
||||
};
|
||||
Executable
+316
@@ -0,0 +1,316 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAXCount.cpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include "SAXCount.hpp"
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <fstream>
|
||||
#else
|
||||
#include <fstream.h>
|
||||
#endif
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void usage()
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
||||
" SAXCount [options] <XML file | List file>\n\n"
|
||||
"This program invokes the SAX Parser, and then prints the\n"
|
||||
"number of elements, attributes, spaces and characters found\n"
|
||||
"in each XML file, using SAX API.\n\n"
|
||||
"Options:\n"
|
||||
" -l Indicate the input file is a List File that has a list of xml files.\n"
|
||||
" Default to off (Input file is an XML file).\n"
|
||||
" -v=xxx Validation scheme [always | never | auto*].\n"
|
||||
" -n Enable namespace processing. Defaults to off.\n"
|
||||
" -s Enable schema processing. Defaults to off.\n"
|
||||
" -f Enable full schema constraint checking. Defaults to off.\n"
|
||||
" -locale=ll_CC specify the locale, default: en_US.\n"
|
||||
" -? Show this help.\n\n"
|
||||
" * = Default if not provided explicitly.\n"
|
||||
<< XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Program entry point
|
||||
// ---------------------------------------------------------------------------
|
||||
int main(int argC, char* argV[])
|
||||
{
|
||||
|
||||
// Check command line and extract arguments.
|
||||
if (argC < 2)
|
||||
{
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* xmlFile = 0;
|
||||
SAXParser::ValSchemes valScheme = SAXParser::Val_Auto;
|
||||
bool doNamespaces = false;
|
||||
bool doSchema = false;
|
||||
bool schemaFullChecking = false;
|
||||
bool doList = false;
|
||||
bool errorOccurred = false;
|
||||
bool recognizeNEL = false;
|
||||
char localeStr[64];
|
||||
memset(localeStr, 0, sizeof localeStr);
|
||||
|
||||
int argInd;
|
||||
for (argInd = 1; argInd < argC; argInd++)
|
||||
{
|
||||
// Break out on first parm not starting with a dash
|
||||
if (argV[argInd][0] != '-')
|
||||
break;
|
||||
|
||||
// Watch for special case help request
|
||||
if (!strcmp(argV[argInd], "-?"))
|
||||
{
|
||||
usage();
|
||||
return 2;
|
||||
}
|
||||
else if (!strncmp(argV[argInd], "-v=", 3)
|
||||
|| !strncmp(argV[argInd], "-V=", 3))
|
||||
{
|
||||
const char* const parm = &argV[argInd][3];
|
||||
|
||||
if (!strcmp(parm, "never"))
|
||||
valScheme = SAXParser::Val_Never;
|
||||
else if (!strcmp(parm, "auto"))
|
||||
valScheme = SAXParser::Val_Auto;
|
||||
else if (!strcmp(parm, "always"))
|
||||
valScheme = SAXParser::Val_Always;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -v= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-n")
|
||||
|| !strcmp(argV[argInd], "-N"))
|
||||
{
|
||||
doNamespaces = true;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-s")
|
||||
|| !strcmp(argV[argInd], "-S"))
|
||||
{
|
||||
doSchema = true;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-f")
|
||||
|| !strcmp(argV[argInd], "-F"))
|
||||
{
|
||||
schemaFullChecking = true;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-l")
|
||||
|| !strcmp(argV[argInd], "-L"))
|
||||
{
|
||||
doList = true;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-special:nel"))
|
||||
{
|
||||
// turning this on will lead to non-standard compliance behaviour
|
||||
// it will recognize the unicode character 0x85 as new line character
|
||||
// instead of regular character as specified in XML 1.0
|
||||
// do not turn this on unless really necessary
|
||||
recognizeNEL = true;
|
||||
}
|
||||
else if (!strncmp(argV[argInd], "-locale=", 8))
|
||||
{
|
||||
// Get out the end of line
|
||||
strcpy(localeStr, &(argV[argInd][8]));
|
||||
}
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[argInd]
|
||||
<< "', ignoring it\n" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// There should at least one parameter left, and that
|
||||
// should be the file name(s).
|
||||
//
|
||||
if (argInd == argC)
|
||||
{
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Initialize the XML4C2 system
|
||||
try
|
||||
{
|
||||
if (strlen(localeStr))
|
||||
{
|
||||
XMLPlatformUtils::Initialize(localeStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
XMLPlatformUtils::Initialize();
|
||||
}
|
||||
|
||||
if (recognizeNEL)
|
||||
{
|
||||
XMLPlatformUtils::recognizeNEL(recognizeNEL);
|
||||
}
|
||||
}
|
||||
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
|
||||
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Create a SAX parser object. Then, according to what we were told on
|
||||
// the command line, set it to validate or not.
|
||||
//
|
||||
SAXParser* parser = new SAXParser;
|
||||
|
||||
parser->setValidationScheme(valScheme);
|
||||
parser->setDoNamespaces(doNamespaces);
|
||||
parser->setDoSchema(doSchema);
|
||||
parser->setValidationSchemaFullChecking(schemaFullChecking);
|
||||
|
||||
//
|
||||
// Create our SAX handler object and install it on the parser, as the
|
||||
// document and error handler.
|
||||
//
|
||||
SAXCountHandlers handler;
|
||||
parser->setDocumentHandler(&handler);
|
||||
parser->setErrorHandler(&handler);
|
||||
|
||||
|
||||
//
|
||||
// Get the starting time and kick off the parse of the indicated
|
||||
// file. Catch any exceptions that might propogate out of it.
|
||||
//
|
||||
unsigned long duration;
|
||||
|
||||
XERCES_STD_QUALIFIER ifstream fin;
|
||||
|
||||
// the input is a list file
|
||||
if (doList)
|
||||
fin.open(argV[argInd]);
|
||||
|
||||
if (fin.fail()) {
|
||||
XERCES_STD_QUALIFIER cerr <<"Cannot open the list file: " << argV[argInd] << XERCES_STD_QUALIFIER endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
char fURI[1000];
|
||||
//initialize the array to zeros
|
||||
memset(fURI,0,sizeof(fURI));
|
||||
|
||||
if (doList) {
|
||||
if (! fin.eof() ) {
|
||||
fin.getline (fURI, sizeof(fURI));
|
||||
if (!*fURI)
|
||||
continue;
|
||||
else {
|
||||
xmlFile = fURI;
|
||||
XERCES_STD_QUALIFIER cerr << "==Parsing== " << xmlFile << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
else {
|
||||
if (argInd < argC)
|
||||
{
|
||||
xmlFile = argV[argInd];
|
||||
argInd++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
//reset error count first
|
||||
handler.resetErrors();
|
||||
|
||||
try
|
||||
{
|
||||
const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
|
||||
parser->parse(xmlFile);
|
||||
const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
|
||||
duration = endMillis - startMillis;
|
||||
}
|
||||
catch (const OutOfMemoryException&)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
|
||||
errorOccurred = true;
|
||||
continue;
|
||||
}
|
||||
catch (const XMLException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << xmlFile << "'\n"
|
||||
<< "Exception message is: \n"
|
||||
<< StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
|
||||
errorOccurred = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
catch (...)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nUnexpected exception during parsing: '" << xmlFile << "'\n";
|
||||
errorOccurred = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Print out the stats that we collected and time taken
|
||||
if (!handler.getSawErrors())
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << xmlFile << ": " << duration << " ms ("
|
||||
<< handler.getElementCount() << " elems, "
|
||||
<< handler.getAttrCount() << " attrs, "
|
||||
<< handler.getSpaceCount() << " spaces, "
|
||||
<< handler.getCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
else
|
||||
errorOccurred = true;
|
||||
}
|
||||
|
||||
if (doList)
|
||||
fin.close();
|
||||
|
||||
//
|
||||
// Delete the parser itself. Must be done prior to calling Terminate, below.
|
||||
//
|
||||
delete parser;
|
||||
|
||||
// And call the termination method
|
||||
XMLPlatformUtils::Terminate();
|
||||
|
||||
if (errorOccurred)
|
||||
return 4;
|
||||
else
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAXCount.hpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes for all the program files to see
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
#include <xercesc/parsers/SAXParser.hpp>
|
||||
#include "SAXCountHandlers.hpp"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple class that lets us do easy (though not terribly efficient)
|
||||
// trancoding of XMLCh data to local code page for display.
|
||||
// ---------------------------------------------------------------------------
|
||||
class StrX
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StrX(const XMLCh* const toTranscode)
|
||||
{
|
||||
// Call the private transcoding method
|
||||
fLocalForm = XMLString::transcode(toTranscode);
|
||||
}
|
||||
|
||||
~StrX()
|
||||
{
|
||||
XMLString::release(&fLocalForm);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
const char* localForm() const
|
||||
{
|
||||
return fLocalForm;
|
||||
}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fLocalForm
|
||||
// This is the local code page form of the string.
|
||||
// -----------------------------------------------------------------------
|
||||
char* fLocalForm;
|
||||
};
|
||||
|
||||
inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
||||
{
|
||||
target << toDump.localForm();
|
||||
return target;
|
||||
}
|
||||
Executable
+113
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAXCountHandlers.cpp 557282 2007-07-18 14:54:15Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include "SAXCount.hpp"
|
||||
#include <xercesc/sax/AttributeList.hpp>
|
||||
#include <xercesc/sax/SAXParseException.hpp>
|
||||
#include <xercesc/sax/SAXException.hpp>
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAXCountHandlers: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
SAXCountHandlers::SAXCountHandlers() :
|
||||
|
||||
fAttrCount(0)
|
||||
, fCharacterCount(0)
|
||||
, fElementCount(0)
|
||||
, fSpaceCount(0)
|
||||
, fSawErrors(false)
|
||||
{
|
||||
}
|
||||
|
||||
SAXCountHandlers::~SAXCountHandlers()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAXCountHandlers: Implementation of the SAX DocumentHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void SAXCountHandlers::startElement(const XMLCh* const /* name */
|
||||
, AttributeList& attributes)
|
||||
{
|
||||
fElementCount++;
|
||||
fAttrCount += attributes.getLength();
|
||||
}
|
||||
|
||||
void SAXCountHandlers::characters( const XMLCh* const /* chars */
|
||||
, const XMLSize_t length)
|
||||
{
|
||||
fCharacterCount += length;
|
||||
}
|
||||
|
||||
void SAXCountHandlers::ignorableWhitespace( const XMLCh* const /* chars */
|
||||
, const XMLSize_t length)
|
||||
{
|
||||
fSpaceCount += length;
|
||||
}
|
||||
|
||||
void SAXCountHandlers::resetDocument()
|
||||
{
|
||||
fAttrCount = 0;
|
||||
fCharacterCount = 0;
|
||||
fElementCount = 0;
|
||||
fSpaceCount = 0;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAXCountHandlers: Overrides of the SAX ErrorHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void SAXCountHandlers::error(const SAXParseException& e)
|
||||
{
|
||||
fSawErrors = true;
|
||||
XERCES_STD_QUALIFIER cerr << "\nError at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void SAXCountHandlers::fatalError(const SAXParseException& e)
|
||||
{
|
||||
fSawErrors = true;
|
||||
XERCES_STD_QUALIFIER cerr << "\nFatal Error at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void SAXCountHandlers::warning(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nWarning at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void SAXCountHandlers::resetErrors()
|
||||
{
|
||||
fSawErrors = false;
|
||||
}
|
||||
Executable
+111
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAXCountHandlers.hpp 679377 2008-07-24 11:56:42Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/sax/HandlerBase.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
class AttributeList;
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
class SAXCountHandlers : public HandlerBase
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
SAXCountHandlers();
|
||||
~SAXCountHandlers();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t getElementCount() const
|
||||
{
|
||||
return fElementCount;
|
||||
}
|
||||
|
||||
XMLSize_t getAttrCount() const
|
||||
{
|
||||
return fAttrCount;
|
||||
}
|
||||
|
||||
XMLSize_t getCharacterCount() const
|
||||
{
|
||||
return fCharacterCount;
|
||||
}
|
||||
|
||||
bool getSawErrors() const
|
||||
{
|
||||
return fSawErrors;
|
||||
}
|
||||
|
||||
XMLSize_t getSpaceCount() const
|
||||
{
|
||||
return fSpaceCount;
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the SAX DocumentHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void startElement(const XMLCh* const name, AttributeList& attributes);
|
||||
void characters(const XMLCh* const chars, const XMLSize_t length);
|
||||
void ignorableWhitespace(const XMLCh* const chars, const XMLSize_t length);
|
||||
void resetDocument();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the SAX ErrorHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void warning(const SAXParseException& exc);
|
||||
void error(const SAXParseException& exc);
|
||||
void fatalError(const SAXParseException& exc);
|
||||
void resetErrors();
|
||||
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fAttrCount
|
||||
// fCharacterCount
|
||||
// fElementCount
|
||||
// fSpaceCount
|
||||
// These are just counters that are run upwards based on the input
|
||||
// from the document handlers.
|
||||
//
|
||||
// fSawErrors
|
||||
// This is set by the error handlers, and is queryable later to
|
||||
// see if any errors occured.
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t fAttrCount;
|
||||
XMLSize_t fCharacterCount;
|
||||
XMLSize_t fElementCount;
|
||||
XMLSize_t fSpaceCount;
|
||||
bool fSawErrors;
|
||||
};
|
||||
Executable
+266
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAXPrint.cpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/TransService.hpp>
|
||||
#include <xercesc/parsers/SAXParser.hpp>
|
||||
#include "SAXPrint.hpp"
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local data
|
||||
//
|
||||
// doNamespaces
|
||||
// Indicates whether namespace processing should be enabled or not.
|
||||
// Defaults to disabled.
|
||||
//
|
||||
// doSchema
|
||||
// Indicates whether schema processing should be enabled or not.
|
||||
// Defaults to disabled.
|
||||
//
|
||||
// schemaFullChecking
|
||||
// Indicates whether full schema constraint checking should be enabled or not.
|
||||
// Defaults to disabled.
|
||||
//
|
||||
// encodingName
|
||||
// The encoding we are to output in. If not set on the command line,
|
||||
// then it is defaulted to LATIN1.
|
||||
//
|
||||
// xmlFile
|
||||
// The path to the file to parser. Set via command line.
|
||||
//
|
||||
// valScheme
|
||||
// Indicates what validation scheme to use. It defaults to 'auto', but
|
||||
// can be set via the -v= command.
|
||||
// ---------------------------------------------------------------------------
|
||||
static bool doNamespaces = false;
|
||||
static bool doSchema = false;
|
||||
static bool schemaFullChecking = false;
|
||||
static const char* encodingName = "LATIN1";
|
||||
static XMLFormatter::UnRepFlags unRepFlags = XMLFormatter::UnRep_CharRef;
|
||||
static char* xmlFile = 0;
|
||||
static SAXParser::ValSchemes valScheme = SAXParser::Val_Auto;
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
static void usage()
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
||||
" SAXPrint [options] <XML file>\n\n"
|
||||
"This program invokes the SAX Parser, and then prints the\n"
|
||||
"data returned by the various SAX handlers for the specified\n"
|
||||
"XML file.\n\n"
|
||||
"Options:\n"
|
||||
" -u=xxx Handle unrepresentable chars [fail | rep | ref*].\n"
|
||||
" -v=xxx Validation scheme [always | never | auto*].\n"
|
||||
" -n Enable namespace processing.\n"
|
||||
" -s Enable schema processing.\n"
|
||||
" -f Enable full schema constraint checking.\n"
|
||||
" -x=XXX Use a particular encoding for output (LATIN1*).\n"
|
||||
" -? Show this help.\n\n"
|
||||
" * = Default if not provided explicitly.\n\n"
|
||||
"The parser has intrinsic support for the following encodings:\n"
|
||||
" UTF-8, USASCII, ISO8859-1, UTF-16[BL]E, UCS-4[BL]E,\n"
|
||||
" WINDOWS-1252, IBM1140, IBM037, IBM1047.\n"
|
||||
<< XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Program entry point
|
||||
// ---------------------------------------------------------------------------
|
||||
int main(int argC, char* argV[])
|
||||
{
|
||||
// Initialize the XML4C2 system
|
||||
try
|
||||
{
|
||||
XMLPlatformUtils::Initialize();
|
||||
}
|
||||
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Error during initialization! :\n"
|
||||
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check command line and extract arguments.
|
||||
if (argC < 2)
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int parmInd;
|
||||
for (parmInd = 1; parmInd < argC; parmInd++)
|
||||
{
|
||||
// Break out on first parm not starting with a dash
|
||||
if (argV[parmInd][0] != '-')
|
||||
break;
|
||||
|
||||
// Watch for special case help request
|
||||
if (!strcmp(argV[parmInd], "-?"))
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-v=", 3)
|
||||
|| !strncmp(argV[parmInd], "-V=", 3))
|
||||
{
|
||||
const char* const parm = &argV[parmInd][3];
|
||||
|
||||
if (!strcmp(parm, "never"))
|
||||
valScheme = SAXParser::Val_Never;
|
||||
else if (!strcmp(parm, "auto"))
|
||||
valScheme = SAXParser::Val_Auto;
|
||||
else if (!strcmp(parm, "always"))
|
||||
valScheme = SAXParser::Val_Always;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -v= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-n")
|
||||
|| !strcmp(argV[parmInd], "-N"))
|
||||
{
|
||||
doNamespaces = true;
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-s")
|
||||
|| !strcmp(argV[parmInd], "-S"))
|
||||
{
|
||||
doSchema = true;
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-f")
|
||||
|| !strcmp(argV[parmInd], "-F"))
|
||||
{
|
||||
schemaFullChecking = true;
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-x=", 3)
|
||||
|| !strncmp(argV[parmInd], "-X=", 3))
|
||||
{
|
||||
// Get out the encoding name
|
||||
encodingName = &argV[parmInd][3];
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-u=", 3)
|
||||
|| !strncmp(argV[parmInd], "-U=", 3))
|
||||
{
|
||||
const char* const parm = &argV[parmInd][3];
|
||||
|
||||
if (!strcmp(parm, "fail"))
|
||||
unRepFlags = XMLFormatter::UnRep_Fail;
|
||||
else if (!strcmp(parm, "rep"))
|
||||
unRepFlags = XMLFormatter::UnRep_Replace;
|
||||
else if (!strcmp(parm, "ref"))
|
||||
unRepFlags = XMLFormatter::UnRep_CharRef;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -u= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[parmInd]
|
||||
<< "', ignoring it\n" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// And now we have to have only one parameter left and it must be
|
||||
// the file name.
|
||||
//
|
||||
if (parmInd + 1 != argC)
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 1;
|
||||
}
|
||||
xmlFile = argV[parmInd];
|
||||
int errorCount = 0;
|
||||
|
||||
//
|
||||
// Create a SAX parser object. Then, according to what we were told on
|
||||
// the command line, set it to validate or not.
|
||||
//
|
||||
SAXParser* parser = new SAXParser;
|
||||
parser->setValidationScheme(valScheme);
|
||||
parser->setDoNamespaces(doNamespaces);
|
||||
parser->setDoSchema(doSchema);
|
||||
parser->setValidationSchemaFullChecking(schemaFullChecking);
|
||||
|
||||
//
|
||||
// Create the handler object and install it as the document and error
|
||||
// handler for the parser-> Then parse the file and catch any exceptions
|
||||
// that propogate out
|
||||
//
|
||||
int errorCode = 0;
|
||||
try
|
||||
{
|
||||
SAXPrintHandlers handler(encodingName, unRepFlags);
|
||||
parser->setDocumentHandler(&handler);
|
||||
parser->setErrorHandler(&handler);
|
||||
parser->parse(xmlFile);
|
||||
errorCount = parser->getErrorCount();
|
||||
}
|
||||
catch (const OutOfMemoryException&)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 5;
|
||||
}
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nAn error occurred\n Error: "
|
||||
<< StrX(toCatch.getMessage())
|
||||
<< "\n" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 4;
|
||||
}
|
||||
if(errorCode) {
|
||||
XMLPlatformUtils::Terminate();
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
//
|
||||
// Delete the parser itself. Must be done prior to calling Terminate, below.
|
||||
//
|
||||
delete parser;
|
||||
|
||||
// And call the termination method
|
||||
XMLPlatformUtils::Terminate();
|
||||
|
||||
if (errorCount > 0)
|
||||
return 4;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAXPrint.hpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes for all the program files to see
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <string.h>
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include "SAXPrintHandlers.hpp"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple class that lets us do easy (though not terribly efficient)
|
||||
// trancoding of XMLCh data to local code page for display.
|
||||
// ---------------------------------------------------------------------------
|
||||
class StrX
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StrX(const XMLCh* const toTranscode)
|
||||
{
|
||||
// Call the private transcoding method
|
||||
fLocalForm = XMLString::transcode(toTranscode);
|
||||
}
|
||||
|
||||
~StrX()
|
||||
{
|
||||
XMLString::release(&fLocalForm);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
const char* localForm() const
|
||||
{
|
||||
return fLocalForm;
|
||||
}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fLocalForm
|
||||
// This is the local code page form of the string.
|
||||
// -----------------------------------------------------------------------
|
||||
char* fLocalForm;
|
||||
};
|
||||
|
||||
inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
||||
{
|
||||
target << toDump.localForm();
|
||||
return target;
|
||||
}
|
||||
Executable
+227
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAXPrintHandlers.cpp 676911 2008-07-15 13:27:32Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/XMLUniDefs.hpp>
|
||||
#include <xercesc/sax/AttributeList.hpp>
|
||||
#include "SAXPrint.hpp"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local const data
|
||||
//
|
||||
// Note: This is the 'safe' way to do these strings. If you compiler supports
|
||||
// L"" style strings, and portability is not a concern, you can use
|
||||
// those types constants directly.
|
||||
// ---------------------------------------------------------------------------
|
||||
static const XMLCh gEndElement[] = { chOpenAngle, chForwardSlash, chNull };
|
||||
static const XMLCh gEndPI[] = { chQuestion, chCloseAngle, chNull };
|
||||
static const XMLCh gStartPI[] = { chOpenAngle, chQuestion, chNull };
|
||||
static const XMLCh gXMLDecl1[] =
|
||||
{
|
||||
chOpenAngle, chQuestion, chLatin_x, chLatin_m, chLatin_l
|
||||
, chSpace, chLatin_v, chLatin_e, chLatin_r, chLatin_s, chLatin_i
|
||||
, chLatin_o, chLatin_n, chEqual, chDoubleQuote, chDigit_1, chPeriod
|
||||
, chDigit_0, chDoubleQuote, chSpace, chLatin_e, chLatin_n, chLatin_c
|
||||
, chLatin_o, chLatin_d, chLatin_i, chLatin_n, chLatin_g, chEqual
|
||||
, chDoubleQuote, chNull
|
||||
};
|
||||
|
||||
static const XMLCh gXMLDecl2[] =
|
||||
{
|
||||
chDoubleQuote, chQuestion, chCloseAngle
|
||||
, chLF, chNull
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAXPrintHandlers: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
SAXPrintHandlers::SAXPrintHandlers( const char* const encodingName
|
||||
, const XMLFormatter::UnRepFlags unRepFlags) :
|
||||
|
||||
fFormatter
|
||||
(
|
||||
encodingName
|
||||
, 0
|
||||
, this
|
||||
, XMLFormatter::NoEscapes
|
||||
, unRepFlags
|
||||
)
|
||||
{
|
||||
//
|
||||
// Go ahead and output an XML Decl with our known encoding. This
|
||||
// is not the best answer, but its the best we can do until we
|
||||
// have SAX2 support.
|
||||
//
|
||||
fFormatter << gXMLDecl1 << fFormatter.getEncodingName() << gXMLDecl2;
|
||||
}
|
||||
|
||||
SAXPrintHandlers::~SAXPrintHandlers()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAXPrintHandlers: Overrides of the output formatter target interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void SAXPrintHandlers::writeChars(const XMLByte* const /* toWrite */)
|
||||
{
|
||||
}
|
||||
|
||||
void SAXPrintHandlers::writeChars(const XMLByte* const toWrite,
|
||||
const XMLSize_t count,
|
||||
XMLFormatter* const /* formatter */)
|
||||
{
|
||||
// For this one, just dump them to the standard output
|
||||
// Surprisingly, Solaris was the only platform on which
|
||||
// required the char* cast to print out the string correctly.
|
||||
// Without the cast, it was printing the pointer value in hex.
|
||||
// Quite annoying, considering every other platform printed
|
||||
// the string with the explicit cast to char* below.
|
||||
XERCES_STD_QUALIFIER cout.write((char *) toWrite, (int) count);
|
||||
XERCES_STD_QUALIFIER cout.flush();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAXPrintHandlers: Overrides of the SAX ErrorHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void SAXPrintHandlers::error(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void SAXPrintHandlers::fatalError(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nFatal Error at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void SAXPrintHandlers::warning(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nWarning at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAXPrintHandlers: Overrides of the SAX DTDHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void SAXPrintHandlers::unparsedEntityDecl(const XMLCh* const /* name */
|
||||
, const XMLCh* const /* publicId */
|
||||
, const XMLCh* const /* systemId */
|
||||
, const XMLCh* const /* notationName */)
|
||||
{
|
||||
// Not used at this time
|
||||
}
|
||||
|
||||
|
||||
void SAXPrintHandlers::notationDecl(const XMLCh* const /* name */
|
||||
, const XMLCh* const /* publicId */
|
||||
, const XMLCh* const /* systemId */)
|
||||
{
|
||||
// Not used at this time
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SAXPrintHandlers: Overrides of the SAX DocumentHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void SAXPrintHandlers::characters(const XMLCh* const chars
|
||||
, const XMLSize_t length)
|
||||
{
|
||||
fFormatter.formatBuf(chars, length, XMLFormatter::CharEscapes);
|
||||
}
|
||||
|
||||
|
||||
void SAXPrintHandlers::endDocument()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SAXPrintHandlers::endElement(const XMLCh* const name)
|
||||
{
|
||||
// No escapes are legal here
|
||||
fFormatter << XMLFormatter::NoEscapes << gEndElement << name << chCloseAngle;
|
||||
}
|
||||
|
||||
|
||||
void SAXPrintHandlers::ignorableWhitespace( const XMLCh* const chars
|
||||
,const XMLSize_t length)
|
||||
{
|
||||
fFormatter.formatBuf(chars, length, XMLFormatter::NoEscapes);
|
||||
}
|
||||
|
||||
|
||||
void SAXPrintHandlers::processingInstruction(const XMLCh* const target
|
||||
, const XMLCh* const data)
|
||||
{
|
||||
fFormatter << XMLFormatter::NoEscapes << gStartPI << target;
|
||||
if (data)
|
||||
fFormatter << chSpace << data;
|
||||
fFormatter << XMLFormatter::NoEscapes << gEndPI;
|
||||
}
|
||||
|
||||
|
||||
void SAXPrintHandlers::startDocument()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SAXPrintHandlers::startElement(const XMLCh* const name
|
||||
, AttributeList& attributes)
|
||||
{
|
||||
// The name has to be representable without any escapes
|
||||
fFormatter << XMLFormatter::NoEscapes
|
||||
<< chOpenAngle << name;
|
||||
|
||||
XMLSize_t len = attributes.getLength();
|
||||
for (XMLSize_t index = 0; index < len; index++)
|
||||
{
|
||||
//
|
||||
// Again the name has to be completely representable. But the
|
||||
// attribute can have refs and requires the attribute style
|
||||
// escaping.
|
||||
//
|
||||
fFormatter << XMLFormatter::NoEscapes
|
||||
<< chSpace << attributes.getName(index)
|
||||
<< chEqual << chDoubleQuote
|
||||
<< XMLFormatter::AttrEscapes
|
||||
<< attributes.getValue(index)
|
||||
<< XMLFormatter::NoEscapes
|
||||
<< chDoubleQuote;
|
||||
}
|
||||
fFormatter << chCloseAngle;
|
||||
}
|
||||
Executable
+123
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SAXPrintHandlers.hpp 557282 2007-07-18 14:54:15Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
#include <xercesc/sax/HandlerBase.hpp>
|
||||
#include <xercesc/framework/XMLFormatter.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
class SAXPrintHandlers : public HandlerBase, private XMLFormatTarget
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors
|
||||
// -----------------------------------------------------------------------
|
||||
SAXPrintHandlers
|
||||
(
|
||||
const char* const encodingName
|
||||
, const XMLFormatter::UnRepFlags unRepFlags
|
||||
);
|
||||
~SAXPrintHandlers();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementations of the format target interface
|
||||
// -----------------------------------------------------------------------
|
||||
void writeChars
|
||||
(
|
||||
const XMLByte* const toWrite
|
||||
);
|
||||
|
||||
virtual void writeChars
|
||||
(
|
||||
const XMLByte* const toWrite
|
||||
, const XMLSize_t count
|
||||
, XMLFormatter* const formatter
|
||||
);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementations of the SAX DocumentHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void endDocument();
|
||||
|
||||
void endElement(const XMLCh* const name);
|
||||
|
||||
void characters(const XMLCh* const chars, const XMLSize_t length);
|
||||
|
||||
void ignorableWhitespace
|
||||
(
|
||||
const XMLCh* const chars
|
||||
, const XMLSize_t length
|
||||
);
|
||||
|
||||
void processingInstruction
|
||||
(
|
||||
const XMLCh* const target
|
||||
, const XMLCh* const data
|
||||
);
|
||||
|
||||
void startDocument();
|
||||
|
||||
void startElement(const XMLCh* const name, AttributeList& attributes);
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementations of the SAX ErrorHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void warning(const SAXParseException& exc);
|
||||
void error(const SAXParseException& exc);
|
||||
void fatalError(const SAXParseException& exc);
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementation of the SAX DTDHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void notationDecl
|
||||
(
|
||||
const XMLCh* const name
|
||||
, const XMLCh* const publicId
|
||||
, const XMLCh* const systemId
|
||||
);
|
||||
|
||||
void unparsedEntityDecl
|
||||
(
|
||||
const XMLCh* const name
|
||||
, const XMLCh* const publicId
|
||||
, const XMLCh* const systemId
|
||||
, const XMLCh* const notationName
|
||||
);
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fFormatter
|
||||
// This is the formatter object that is used to output the data
|
||||
// to the target. It is set up to format to the standard output
|
||||
// stream.
|
||||
// -----------------------------------------------------------------------
|
||||
XMLFormatter fFormatter;
|
||||
};
|
||||
Executable
+564
@@ -0,0 +1,564 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SCMPrint.cpp 676911 2008-07-15 13:27:32Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/sax2/SAX2XMLReader.hpp>
|
||||
#include <xercesc/sax2/XMLReaderFactory.hpp>
|
||||
#include <xercesc/framework/XMLGrammarPoolImpl.hpp>
|
||||
#include <xercesc/framework/psvi/XSModel.hpp>
|
||||
#include <xercesc/framework/psvi/XSElementDeclaration.hpp>
|
||||
#include <xercesc/framework/psvi/XSTypeDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSParticle.hpp>
|
||||
#include <xercesc/framework/psvi/XSModelGroup.hpp>
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#include <fstream.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
#include <xercesc/sax2/DefaultHandler.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Forward references
|
||||
// ---------------------------------------------------------------------------
|
||||
static void usage();
|
||||
|
||||
void processElements(XSNamedMap<XSObject> *xsElements);
|
||||
void processTypeDefinitions(XSNamedMap<XSObject> *xsTypeDefs);
|
||||
void printBasic(XSObject *xsObject, const char *type);
|
||||
void printCompositorTypeConnector(XSModelGroup::COMPOSITOR_TYPE type);
|
||||
void processSimpleTypeDefinition(XSSimpleTypeDefinition * xsSimpleTypeDef);
|
||||
void processComplexTypeDefinition(XSComplexTypeDefinition *xsComplexTypeDef);
|
||||
void processParticle(XSParticle *xsParticle);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple class that lets us do easy (though not terribly efficient)
|
||||
// trancoding of XMLCh data to local code page for display.
|
||||
// ---------------------------------------------------------------------------
|
||||
class StrX
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StrX(const XMLCh* const toTranscode)
|
||||
{
|
||||
// Call the private transcoding method
|
||||
fLocalForm = XMLString::transcode(toTranscode);
|
||||
}
|
||||
|
||||
~StrX()
|
||||
{
|
||||
XMLString::release(&fLocalForm);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
const char* localForm() const
|
||||
{
|
||||
return fLocalForm;
|
||||
}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fLocalForm
|
||||
// This is the local code page form of the string.
|
||||
// -----------------------------------------------------------------------
|
||||
char* fLocalForm;
|
||||
};
|
||||
|
||||
inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
||||
{
|
||||
target << toDump.localForm();
|
||||
return target;
|
||||
}
|
||||
|
||||
class SCMPrintHandler : public DefaultHandler
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
SCMPrintHandler();
|
||||
~SCMPrintHandler();
|
||||
|
||||
bool getSawErrors() const
|
||||
{
|
||||
return fSawErrors;
|
||||
}
|
||||
|
||||
void warning(const SAXParseException& exc);
|
||||
void error(const SAXParseException& exc);
|
||||
void fatalError(const SAXParseException& exc);
|
||||
void resetErrors();
|
||||
|
||||
|
||||
private:
|
||||
bool fSawErrors;
|
||||
};
|
||||
|
||||
SCMPrintHandler::SCMPrintHandler() :
|
||||
fSawErrors(false)
|
||||
{
|
||||
}
|
||||
|
||||
SCMPrintHandler::~SCMPrintHandler()
|
||||
{
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SCMPrintHandler: Overrides of the SAX ErrorHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void SCMPrintHandler::error(const SAXParseException& e)
|
||||
{
|
||||
fSawErrors = true;
|
||||
XERCES_STD_QUALIFIER cerr << "\nError at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void SCMPrintHandler::fatalError(const SAXParseException& e)
|
||||
{
|
||||
fSawErrors = true;
|
||||
XERCES_STD_QUALIFIER cerr << "\nFatal Error at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void SCMPrintHandler::warning(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nWarning at file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void SCMPrintHandler::resetErrors()
|
||||
{
|
||||
fSawErrors = false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
static void usage()
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
||||
" SCMPrint [options] <XSD file | List file>\n\n"
|
||||
"This program parses XML Schema file(s), to show how one can\n"
|
||||
"access the Schema Content Model information.\n\n"
|
||||
"Options:\n"
|
||||
" -f Enable full schema constraint checking processing. Defaults to off.\n"
|
||||
" -l Indicate the input file is a List File that has a list of XSD files.\n"
|
||||
" Default to off (Input file is a XSD file).\n"
|
||||
" -? Show this help.\n\n"
|
||||
<< XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Program entry point
|
||||
// ---------------------------------------------------------------------------
|
||||
int main(int argC, char* argV[])
|
||||
{
|
||||
// Check command line and extract arguments.
|
||||
if (argC < 2)
|
||||
{
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// cannot return out of catch-blocks lest exception-destruction
|
||||
// result in calls to destroyed memory handler!
|
||||
int errorCode = 0;
|
||||
try
|
||||
{
|
||||
XMLPlatformUtils::Initialize();
|
||||
}
|
||||
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
|
||||
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 2;
|
||||
}
|
||||
if(errorCode) {
|
||||
XMLPlatformUtils::Terminate();
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
bool doList = false;
|
||||
bool schemaFullChecking = false;
|
||||
const char* xsdFile = 0;
|
||||
int argInd;
|
||||
|
||||
for (argInd = 1; argInd < argC; argInd++)
|
||||
{
|
||||
// Break out on first parm not starting with a dash
|
||||
if (argV[argInd][0] != '-')
|
||||
break;
|
||||
|
||||
// Watch for special case help request
|
||||
if (!strcmp(argV[argInd], "-?"))
|
||||
{
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-l")
|
||||
|| !strcmp(argV[argInd], "-L"))
|
||||
{
|
||||
doList = true;
|
||||
}
|
||||
else if (!strcmp(argV[argInd], "-f")
|
||||
|| !strcmp(argV[argInd], "-F"))
|
||||
{
|
||||
schemaFullChecking = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[argInd]
|
||||
<< "', ignoring it\n" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// There should be only one and only one parameter left, and that
|
||||
// should be the file name.
|
||||
//
|
||||
if (argInd != argC - 1)
|
||||
{
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
XMLGrammarPool *grammarPool;
|
||||
SAX2XMLReader* parser;
|
||||
try
|
||||
{
|
||||
grammarPool = new XMLGrammarPoolImpl(XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
parser = XMLReaderFactory::createXMLReader(XMLPlatformUtils::fgMemoryManager, grammarPool);
|
||||
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
|
||||
parser->setFeature(XMLUni::fgXercesSchema, true);
|
||||
parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
|
||||
parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, false);
|
||||
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
|
||||
parser->setFeature(XMLUni::fgXercesDynamic, true);
|
||||
parser->setProperty(XMLUni::fgXercesScannerName, (void *)XMLUni::fgSGXMLScanner);
|
||||
|
||||
SCMPrintHandler handler;
|
||||
parser->setErrorHandler(&handler);
|
||||
|
||||
bool more = true;
|
||||
bool parsedOneSchemaOkay = false;
|
||||
XERCES_STD_QUALIFIER ifstream fin;
|
||||
|
||||
// the input is a list file
|
||||
if (doList)
|
||||
fin.open(argV[argInd]);
|
||||
|
||||
if (fin.fail()) {
|
||||
XERCES_STD_QUALIFIER cerr <<"Cannot open the list file: " << argV[argInd] << XERCES_STD_QUALIFIER endl;
|
||||
return 3;
|
||||
}
|
||||
|
||||
while (more)
|
||||
{
|
||||
char fURI[1000];
|
||||
//initialize the array to zeros
|
||||
memset(fURI,0,sizeof(fURI));
|
||||
|
||||
if (doList) {
|
||||
if (! fin.eof() ) {
|
||||
fin.getline (fURI, sizeof(fURI));
|
||||
if (!*fURI)
|
||||
continue;
|
||||
else {
|
||||
xsdFile = fURI;
|
||||
XERCES_STD_QUALIFIER cerr << "==Parsing== " << xsdFile << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
else {
|
||||
xsdFile = argV[argInd];
|
||||
more = false;
|
||||
}
|
||||
|
||||
parser->loadGrammar(xsdFile, Grammar::SchemaGrammarType, true);
|
||||
if (handler.getSawErrors())
|
||||
{
|
||||
handler.resetErrors();
|
||||
}
|
||||
else
|
||||
{
|
||||
parsedOneSchemaOkay = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (parsedOneSchemaOkay)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "********** Printing out information from Schema **********" << "\n\n";
|
||||
bool updatedXSModel;
|
||||
XSModel *xsModel = grammarPool->getXSModel(updatedXSModel);
|
||||
if (xsModel)
|
||||
{
|
||||
StringList *namespaces = xsModel->getNamespaces();
|
||||
for (unsigned i = 0; i < namespaces->size(); i++) {
|
||||
|
||||
XERCES_STD_QUALIFIER cout << "Processing Namespace: ";
|
||||
const XMLCh *nameSpace = namespaces->elementAt(i);
|
||||
if (nameSpace && *nameSpace)
|
||||
XERCES_STD_QUALIFIER cout << StrX(nameSpace);
|
||||
XERCES_STD_QUALIFIER cout << "\n============================================" << XERCES_STD_QUALIFIER endl << XERCES_STD_QUALIFIER endl;
|
||||
|
||||
processElements(xsModel->getComponentsByNamespace(XSConstants::ELEMENT_DECLARATION,
|
||||
nameSpace));
|
||||
processTypeDefinitions(xsModel->getComponentsByNamespace(XSConstants::TYPE_DEFINITION,
|
||||
nameSpace));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "No XSModel to print" << "\n\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "Did not parse a schema document cleanly so not printing Schema for Schema XSModel information";
|
||||
}
|
||||
|
||||
XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
catch (const OutOfMemoryException&)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException during parsing: '" << xsdFile << "'\n" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 6;
|
||||
}
|
||||
catch (const XMLException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << xsdFile << "'\n"
|
||||
<< "Exception message is: \n"
|
||||
<< StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 4;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nUnexpected exception during parsing: '" << xsdFile << "'\n" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 5;
|
||||
}
|
||||
|
||||
delete parser;
|
||||
delete grammarPool;
|
||||
XMLPlatformUtils::Terminate();
|
||||
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
void printBasic(XSObject *xsObject, const char *type)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "Name:\t\t\t";
|
||||
const XMLCh *nameSpace = xsObject->getNamespace();
|
||||
if (nameSpace && *nameSpace) {
|
||||
XERCES_STD_QUALIFIER cout << StrX(nameSpace) << ", ";
|
||||
}
|
||||
XERCES_STD_QUALIFIER cout << StrX(xsObject->getName()) << "\n";
|
||||
XERCES_STD_QUALIFIER cout << "Component Type:\t" << type << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void processElements(XSNamedMap<XSObject> *xsElements)
|
||||
{
|
||||
if (!xsElements || xsElements->getLength() == 0) {
|
||||
XERCES_STD_QUALIFIER cout << "no elements\n\n" << XERCES_STD_QUALIFIER endl;
|
||||
return;
|
||||
}
|
||||
for (XMLSize_t i=0; i < xsElements->getLength(); i++) {
|
||||
XSElementDeclaration *xsElement = (XSElementDeclaration *)xsElements->item(i);
|
||||
printBasic(xsElement, "Element");
|
||||
|
||||
// Content Model
|
||||
XSTypeDefinition *xsTypeDef = xsElement->getTypeDefinition();
|
||||
XERCES_STD_QUALIFIER cout << "Content Model" << "\n";
|
||||
XERCES_STD_QUALIFIER cout << "\tType:\t";
|
||||
if (xsTypeDef->getTypeCategory() == XSTypeDefinition::SIMPLE_TYPE) {
|
||||
XERCES_STD_QUALIFIER cout << "Simple\n";
|
||||
} else {
|
||||
XERCES_STD_QUALIFIER cout << "Complex\n";
|
||||
}
|
||||
XERCES_STD_QUALIFIER cout << "\tName:\t"
|
||||
<< StrX(xsTypeDef->getName()) << "\n";
|
||||
|
||||
XERCES_STD_QUALIFIER cout << "\n--------------------------------------------" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
|
||||
void processSimpleTypeDefinition(XSSimpleTypeDefinition * xsSimpleTypeDef)
|
||||
{
|
||||
XSTypeDefinition *xsBaseTypeDef = xsSimpleTypeDef->getBaseType();
|
||||
XERCES_STD_QUALIFIER cout << "Base:\t\t\t";
|
||||
XERCES_STD_QUALIFIER cout << StrX(xsBaseTypeDef->getName()) << XERCES_STD_QUALIFIER endl;
|
||||
|
||||
int facets = xsSimpleTypeDef->getDefinedFacets();
|
||||
if (facets) {
|
||||
XERCES_STD_QUALIFIER cout << "Facets:\n";
|
||||
|
||||
if (facets & XSSimpleTypeDefinition::FACET_LENGTH)
|
||||
XERCES_STD_QUALIFIER cout << "\tLength:\t\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_LENGTH)) << XERCES_STD_QUALIFIER endl;
|
||||
if (facets & XSSimpleTypeDefinition::FACET_MINLENGTH)
|
||||
XERCES_STD_QUALIFIER cout << "\tMinLength:\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_MINLENGTH)) << XERCES_STD_QUALIFIER endl;
|
||||
if (facets & XSSimpleTypeDefinition::FACET_MAXLENGTH)
|
||||
XERCES_STD_QUALIFIER cout << "\tMaxLength:\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_MAXLENGTH)) << XERCES_STD_QUALIFIER endl;
|
||||
if (facets & XSSimpleTypeDefinition::FACET_PATTERN) {
|
||||
StringList *lexicalPatterns = xsSimpleTypeDef->getLexicalPattern();
|
||||
if (lexicalPatterns && lexicalPatterns->size()) {
|
||||
XERCES_STD_QUALIFIER cout << "\tPattern:\t\t";
|
||||
for (unsigned i = 0; i < lexicalPatterns->size(); i++) {
|
||||
XERCES_STD_QUALIFIER cout << StrX(lexicalPatterns->elementAt(i));
|
||||
}
|
||||
XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
if (facets & XSSimpleTypeDefinition::FACET_WHITESPACE)
|
||||
XERCES_STD_QUALIFIER cout << "\tWhitespace:\t\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_WHITESPACE)) << XERCES_STD_QUALIFIER endl;
|
||||
if (facets & XSSimpleTypeDefinition::FACET_MAXINCLUSIVE)
|
||||
XERCES_STD_QUALIFIER cout << "\tMaxInclusive:\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_MAXINCLUSIVE)) << XERCES_STD_QUALIFIER endl;
|
||||
if (facets & XSSimpleTypeDefinition::FACET_MAXEXCLUSIVE)
|
||||
XERCES_STD_QUALIFIER cout << "\tMaxExclusive:\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_MAXEXCLUSIVE)) << XERCES_STD_QUALIFIER endl;
|
||||
if (facets & XSSimpleTypeDefinition::FACET_MINEXCLUSIVE)
|
||||
XERCES_STD_QUALIFIER cout << "\tMinExclusive:\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_MINEXCLUSIVE)) << XERCES_STD_QUALIFIER endl;
|
||||
if (facets & XSSimpleTypeDefinition::FACET_MININCLUSIVE)
|
||||
XERCES_STD_QUALIFIER cout << "\tMinInclusive:\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_MININCLUSIVE)) << XERCES_STD_QUALIFIER endl;
|
||||
if (facets & XSSimpleTypeDefinition::FACET_TOTALDIGITS)
|
||||
XERCES_STD_QUALIFIER cout << "\tTotalDigits:\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_TOTALDIGITS)) << XERCES_STD_QUALIFIER endl;
|
||||
if (facets & XSSimpleTypeDefinition::FACET_FRACTIONDIGITS)
|
||||
XERCES_STD_QUALIFIER cout << "\tFractionDigits:\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_FRACTIONDIGITS)) << XERCES_STD_QUALIFIER endl;
|
||||
if (facets & XSSimpleTypeDefinition::FACET_ENUMERATION) {
|
||||
StringList *lexicalEnums = xsSimpleTypeDef->getLexicalEnumeration();
|
||||
if (lexicalEnums && lexicalEnums->size()) {
|
||||
XERCES_STD_QUALIFIER cout << "\tEnumeration:\n";
|
||||
for (unsigned i = 0; i < lexicalEnums->size(); i++) {
|
||||
XERCES_STD_QUALIFIER cout << "\t\t\t" << StrX(lexicalEnums->elementAt(i)) << "\n";
|
||||
}
|
||||
XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void printCompositorTypeConnector(XSModelGroup::COMPOSITOR_TYPE type)
|
||||
{
|
||||
switch (type) {
|
||||
case XSModelGroup::COMPOSITOR_SEQUENCE :
|
||||
XERCES_STD_QUALIFIER cout << ",";
|
||||
break;
|
||||
case XSModelGroup::COMPOSITOR_CHOICE :
|
||||
XERCES_STD_QUALIFIER cout << "|";
|
||||
break;
|
||||
case XSModelGroup::COMPOSITOR_ALL :
|
||||
XERCES_STD_QUALIFIER cout << "*";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void processParticle(XSParticle *xsParticle)
|
||||
{
|
||||
if (!xsParticle) {
|
||||
XERCES_STD_QUALIFIER cout << "xsParticle is NULL";
|
||||
return;
|
||||
}
|
||||
XSParticle::TERM_TYPE termType = xsParticle->getTermType();
|
||||
if (termType == XSParticle::TERM_ELEMENT) {
|
||||
XSElementDeclaration *xsElement = xsParticle->getElementTerm();
|
||||
XERCES_STD_QUALIFIER cout << StrX(xsElement->getName());
|
||||
} else if (termType == XSParticle::TERM_MODELGROUP) {
|
||||
XERCES_STD_QUALIFIER cout << "(";
|
||||
|
||||
XSModelGroup *xsModelGroup = xsParticle->getModelGroupTerm();
|
||||
XSModelGroup::COMPOSITOR_TYPE compositorType = xsModelGroup->getCompositor();
|
||||
XSParticleList *xsParticleList = xsModelGroup->getParticles();
|
||||
for (unsigned i = 0; i < xsParticleList->size()-1; i++) {
|
||||
processParticle(xsParticleList->elementAt(i));
|
||||
printCompositorTypeConnector(compositorType);
|
||||
}
|
||||
processParticle(xsParticleList->elementAt(xsParticleList->size()-1));
|
||||
|
||||
XERCES_STD_QUALIFIER cout << ")";
|
||||
} else if (termType == XSParticle::TERM_WILDCARD) {
|
||||
XERCES_STD_QUALIFIER cout << "* (wildcard)";
|
||||
}
|
||||
}
|
||||
|
||||
void processComplexTypeDefinition(XSComplexTypeDefinition *xsComplexTypeDef)
|
||||
{
|
||||
XSTypeDefinition *xsBaseTypeDef = xsComplexTypeDef->getBaseType();
|
||||
if (xsBaseTypeDef) {
|
||||
XERCES_STD_QUALIFIER cout << "Base:\t\t\t";
|
||||
XERCES_STD_QUALIFIER cout << StrX(xsBaseTypeDef->getName()) << "\n";
|
||||
}
|
||||
|
||||
XERCES_STD_QUALIFIER cout << "Content Model:\t";
|
||||
XSComplexTypeDefinition::CONTENT_TYPE contentType = xsComplexTypeDef->getContentType();
|
||||
if (contentType == XSComplexTypeDefinition::CONTENTTYPE_ELEMENT ||
|
||||
contentType == XSComplexTypeDefinition::CONTENTTYPE_MIXED) {
|
||||
processParticle(xsComplexTypeDef->getParticle());
|
||||
XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
|
||||
void processTypeDefinitions(XSNamedMap<XSObject> *xsTypeDefs)
|
||||
{
|
||||
if (!xsTypeDefs) return;
|
||||
|
||||
for (XMLSize_t i=0; i < xsTypeDefs->getLength(); i++) {
|
||||
XSTypeDefinition *xsTypeDef = (XSTypeDefinition *)xsTypeDefs->item(i);
|
||||
|
||||
printBasic(xsTypeDef, "Type Definition");
|
||||
|
||||
// Content Model
|
||||
XERCES_STD_QUALIFIER cout << "Category:\t";
|
||||
if (xsTypeDef->getTypeCategory() == XSTypeDefinition::SIMPLE_TYPE) {
|
||||
XERCES_STD_QUALIFIER cout << "\tSimple\n";
|
||||
processSimpleTypeDefinition((XSSimpleTypeDefinition *)xsTypeDef);
|
||||
} else {
|
||||
XERCES_STD_QUALIFIER cout << "\tComplex\n";
|
||||
processComplexTypeDefinition((XSComplexTypeDefinition *)xsTypeDef);
|
||||
}
|
||||
|
||||
XERCES_STD_QUALIFIER cout << "\n--------------------------------------------" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
Executable
+519
@@ -0,0 +1,519 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: SEnumVal.cpp 696992 2008-09-19 08:53:47Z amassari $
|
||||
*/
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/NameIdPool.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/framework/XMLValidator.hpp>
|
||||
#include <xercesc/framework/psvi/XSAnnotation.hpp>
|
||||
#include <xercesc/parsers/SAXParser.hpp>
|
||||
#include <xercesc/validators/schema/SchemaValidator.hpp>
|
||||
#include <xercesc/validators/schema/SchemaSymbols.hpp>
|
||||
#include <xercesc/validators/common/ContentSpecNode.hpp>
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Forward references
|
||||
// ---------------------------------------------------------------------------
|
||||
static void usage();
|
||||
|
||||
void process(char* const);
|
||||
void processAttributes( XMLAttDefList& attList, bool margin = false );
|
||||
void processDatatypeValidator( const DatatypeValidator*, bool margin = false
|
||||
);
|
||||
void processContentSpecNode( const ContentSpecNode* specNode, bool margin =
|
||||
false );
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple class that lets us do easy (though not terribly efficient)
|
||||
// trancoding of XMLCh data to local code page for display.
|
||||
// ---------------------------------------------------------------------------
|
||||
class StrX
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StrX(const XMLCh* const toTranscode)
|
||||
{
|
||||
// Call the private transcoding method
|
||||
fLocalForm = XMLString::transcode(toTranscode);
|
||||
}
|
||||
|
||||
~StrX()
|
||||
{
|
||||
XMLString::release(&fLocalForm);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
const char* localForm() const
|
||||
{
|
||||
return fLocalForm;
|
||||
}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fLocalForm
|
||||
// This is the local code page form of the string.
|
||||
// -----------------------------------------------------------------------
|
||||
char* fLocalForm;
|
||||
};
|
||||
|
||||
inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
||||
{
|
||||
target << toDump.localForm();
|
||||
return target;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
static void usage()
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
||||
" SEnumVal <XML file>\n\n"
|
||||
"This program parses a file, then shows how to enumerate the\n"
|
||||
"contents of the Schema Grammar. Essentially, shows how one can\n"
|
||||
"access the Schema information stored in internal data structures.\n"
|
||||
<< XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Program entry point
|
||||
// ---------------------------------------------------------------------------
|
||||
int main(int argC, char* argV[])
|
||||
{
|
||||
// cannot return out of catch-blocks lest exception-destruction
|
||||
// result in calls to destroyed memory handler!
|
||||
int errorCode = 0;
|
||||
// Initialize the XML4C system
|
||||
try
|
||||
{
|
||||
XMLPlatformUtils::Initialize();
|
||||
}
|
||||
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
|
||||
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 1;
|
||||
}
|
||||
if(errorCode) {
|
||||
XMLPlatformUtils::Terminate();
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
// Check command line and extract arguments.
|
||||
// We only have one required parameter, which is the file to process
|
||||
if ((argC != 2) ||
|
||||
(*(argV[1]) == '-'))
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
process(argV[1]);
|
||||
}
|
||||
catch (const OutOfMemoryException&)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 5;
|
||||
}
|
||||
catch (const XMLException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << argV[1] << "'\n"
|
||||
<< "Exception message is: \n"
|
||||
<< StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
|
||||
errorCode = 3;
|
||||
}
|
||||
|
||||
XMLPlatformUtils::Terminate();
|
||||
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
void process(char* const xmlFile)
|
||||
{
|
||||
//
|
||||
// Create a Schema validator to be used for our validation work. Then create
|
||||
// a SAX parser object and pass it our validator. Then, according to what
|
||||
// we were told on the command line, set it to validate or not. He owns
|
||||
// the validator, so we have to allocate it.
|
||||
//
|
||||
SAXParser parser;
|
||||
parser.setValidationScheme(SAXParser::Val_Always);
|
||||
parser.setDoNamespaces(true);
|
||||
parser.setDoSchema(true);
|
||||
|
||||
parser.parse(xmlFile);
|
||||
|
||||
if (parser.getErrorCount())
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nErrors occurred, no output available\n" << XERCES_STD_QUALIFIER endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!parser.getValidator().handlesSchema())
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\n Non schema document, no output available\n" << XERCES_STD_QUALIFIER endl;
|
||||
return;
|
||||
}
|
||||
|
||||
Grammar* rootGrammar = parser.getRootGrammar();
|
||||
if (!rootGrammar || rootGrammar->getGrammarType() != Grammar::SchemaGrammarType)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\n Non schema grammar, no output available\n" << XERCES_STD_QUALIFIER endl;
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Now we will get an enumerator for the element pool from the validator
|
||||
// and enumerate the elements, printing them as we go. For each element
|
||||
// we get an enumerator for its attributes and print them also.
|
||||
//
|
||||
|
||||
SchemaGrammar* grammar = (SchemaGrammar*) rootGrammar;
|
||||
RefHash3KeysIdPoolEnumerator<SchemaElementDecl> elemEnum = grammar->getElemEnumerator();
|
||||
|
||||
if (!elemEnum.hasMoreElements())
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nThe validator has no elements to display\n" << XERCES_STD_QUALIFIER endl;
|
||||
return;
|
||||
}
|
||||
|
||||
while(elemEnum.hasMoreElements())
|
||||
{
|
||||
const SchemaElementDecl& curElem = elemEnum.nextElement();
|
||||
|
||||
// Name
|
||||
XERCES_STD_QUALIFIER cout << "Name:\t\t\t" << StrX(curElem.getFullName()) << "\n";
|
||||
|
||||
// Model Type
|
||||
XERCES_STD_QUALIFIER cout << "Model Type:\t\t";
|
||||
switch( curElem.getModelType() )
|
||||
{
|
||||
case SchemaElementDecl::Empty: XERCES_STD_QUALIFIER cout << "Empty"; break;
|
||||
case SchemaElementDecl::Any: XERCES_STD_QUALIFIER cout << "Any"; break;
|
||||
case SchemaElementDecl::Mixed_Simple: XERCES_STD_QUALIFIER cout << "Mixed_Simple"; break;
|
||||
case SchemaElementDecl::Mixed_Complex: XERCES_STD_QUALIFIER cout << "Mixed_Complex"; break;
|
||||
case SchemaElementDecl::Children: XERCES_STD_QUALIFIER cout << "Children"; break;
|
||||
case SchemaElementDecl::Simple: XERCES_STD_QUALIFIER cout << "Simple"; break;
|
||||
case SchemaElementDecl::ElementOnlyEmpty: XERCES_STD_QUALIFIER cout << "ElementOnlyEmpty"; break;
|
||||
|
||||
default: XERCES_STD_QUALIFIER cout << "Unknown"; break;
|
||||
}
|
||||
|
||||
XERCES_STD_QUALIFIER cout << "\n";
|
||||
|
||||
// Create Reason
|
||||
XERCES_STD_QUALIFIER cout << "Create Reason:\t";
|
||||
switch( curElem.getCreateReason() )
|
||||
{
|
||||
case XMLElementDecl::NoReason: XERCES_STD_QUALIFIER cout << "Empty"; break;
|
||||
case XMLElementDecl::Declared: XERCES_STD_QUALIFIER cout << "Declared"; break;
|
||||
case XMLElementDecl::AttList: XERCES_STD_QUALIFIER cout << "AttList"; break;
|
||||
case XMLElementDecl::InContentModel: XERCES_STD_QUALIFIER cout << "InContentModel"; break;
|
||||
case XMLElementDecl::AsRootElem: XERCES_STD_QUALIFIER cout << "AsRootElem"; break;
|
||||
case XMLElementDecl::JustFaultIn: XERCES_STD_QUALIFIER cout << "JustFaultIn"; break;
|
||||
|
||||
default: XERCES_STD_QUALIFIER cout << "Unknown"; break;
|
||||
}
|
||||
|
||||
XERCES_STD_QUALIFIER cout << "\n";
|
||||
|
||||
// Content Spec Node
|
||||
processContentSpecNode( curElem.getContentSpec() );
|
||||
|
||||
// Misc Flags
|
||||
int mflags = curElem.getMiscFlags();
|
||||
if( mflags !=0 )
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "Misc. Flags:\t";
|
||||
}
|
||||
|
||||
if ( mflags & SchemaSymbols::XSD_NILLABLE )
|
||||
XERCES_STD_QUALIFIER cout << "Nillable ";
|
||||
|
||||
if ( mflags & SchemaSymbols::XSD_ABSTRACT )
|
||||
XERCES_STD_QUALIFIER cout << "Abstract ";
|
||||
|
||||
if ( mflags & SchemaSymbols::XSD_FIXED )
|
||||
XERCES_STD_QUALIFIER cout << "Fixed ";
|
||||
|
||||
if( mflags !=0 )
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\n";
|
||||
}
|
||||
|
||||
// Substitution Name
|
||||
SchemaElementDecl* subsGroup = curElem.getSubstitutionGroupElem();
|
||||
if( subsGroup )
|
||||
{
|
||||
const XMLCh* uriText = parser.getURIText(subsGroup->getURI());
|
||||
XERCES_STD_QUALIFIER cout << "Substitution Name:\t" << StrX(uriText)
|
||||
<< "," << StrX(subsGroup->getBaseName()) << "\n";
|
||||
}
|
||||
|
||||
// Content Model
|
||||
const XMLCh* fmtCntModel = curElem.getFormattedContentModel();
|
||||
if( fmtCntModel != NULL )
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "Content Model:\t" << StrX(fmtCntModel) << "\n";
|
||||
}
|
||||
|
||||
const ComplexTypeInfo* ctype = curElem.getComplexTypeInfo();
|
||||
if( ctype != NULL)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "ComplexType:\n";
|
||||
XERCES_STD_QUALIFIER cout << "\tTypeName:\t" << StrX(ctype->getTypeName()) << "\n";
|
||||
|
||||
ContentSpecNode* cSpecNode = ctype->getContentSpec();
|
||||
processContentSpecNode(cSpecNode, true );
|
||||
}
|
||||
|
||||
// Datatype
|
||||
DatatypeValidator* dtValidator = curElem.getDatatypeValidator();
|
||||
processDatatypeValidator( dtValidator );
|
||||
|
||||
// Get an enumerator for this guy's attributes if any
|
||||
if ( curElem.hasAttDefs() )
|
||||
{
|
||||
processAttributes( curElem.getAttDefList() );
|
||||
}
|
||||
|
||||
XERCES_STD_QUALIFIER cout << "--------------------------------------------";
|
||||
XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl;
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Prints the Attribute's properties
|
||||
//---------------------------------------------------------------------
|
||||
void processAttributes( XMLAttDefList& attList, bool margin )
|
||||
{
|
||||
if ( attList.isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( margin )
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\t";
|
||||
}
|
||||
|
||||
XERCES_STD_QUALIFIER cout << "Attributes:\n";
|
||||
for (unsigned int i=0; i<attList.getAttDefCount(); i++)
|
||||
{
|
||||
// Name
|
||||
SchemaAttDef& curAttDef = (SchemaAttDef&)attList.getAttDef(i);
|
||||
XERCES_STD_QUALIFIER cout << "\tName:\t\t\t" << StrX(curAttDef.getFullName()) << "\n";
|
||||
|
||||
// Type
|
||||
XERCES_STD_QUALIFIER cout << "\tType:\t\t\t";
|
||||
XERCES_STD_QUALIFIER cout << StrX(XMLAttDef::getAttTypeString(curAttDef.getType()));
|
||||
XERCES_STD_QUALIFIER cout << "\n";
|
||||
|
||||
// Default Type
|
||||
XERCES_STD_QUALIFIER cout << "\tDefault Type:\t";
|
||||
XERCES_STD_QUALIFIER cout << StrX(XMLAttDef::getDefAttTypeString(curAttDef.getDefaultType()));
|
||||
XERCES_STD_QUALIFIER cout << "\n";
|
||||
|
||||
// Value
|
||||
if( curAttDef.getValue() )
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\tValue:\t\t\t";
|
||||
XERCES_STD_QUALIFIER cout << StrX(curAttDef.getValue());
|
||||
XERCES_STD_QUALIFIER cout << "\n";
|
||||
}
|
||||
|
||||
// Enum. values
|
||||
if( curAttDef.getEnumeration() )
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\tEnumeration:\t";
|
||||
XERCES_STD_QUALIFIER cout << StrX(curAttDef.getEnumeration());
|
||||
XERCES_STD_QUALIFIER cout << "\n";
|
||||
}
|
||||
|
||||
const DatatypeValidator* dv = curAttDef.getDatatypeValidator();
|
||||
processDatatypeValidator( dv, true );
|
||||
|
||||
XERCES_STD_QUALIFIER cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void processDatatypeValidator( const DatatypeValidator* dtValidator, bool margin )
|
||||
{
|
||||
if( !dtValidator )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if( margin )
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\t";
|
||||
}
|
||||
|
||||
XERCES_STD_QUALIFIER cout << "Base Datatype:\t\t";
|
||||
switch( dtValidator->getType() )
|
||||
{
|
||||
case DatatypeValidator::String: XERCES_STD_QUALIFIER cout << "string"; break;
|
||||
case DatatypeValidator::AnyURI: XERCES_STD_QUALIFIER cout << "AnyURI"; break;
|
||||
case DatatypeValidator::QName: XERCES_STD_QUALIFIER cout << "QName"; break;
|
||||
case DatatypeValidator::Name: XERCES_STD_QUALIFIER cout << "Name"; break;
|
||||
case DatatypeValidator::NCName: XERCES_STD_QUALIFIER cout << "NCName"; break;
|
||||
case DatatypeValidator::Boolean: XERCES_STD_QUALIFIER cout << "Boolean"; break;
|
||||
case DatatypeValidator::Float: XERCES_STD_QUALIFIER cout << "Float"; break;
|
||||
case DatatypeValidator::Double: XERCES_STD_QUALIFIER cout << "Double"; break;
|
||||
case DatatypeValidator::Decimal: XERCES_STD_QUALIFIER cout << "Decimal"; break;
|
||||
case DatatypeValidator::HexBinary: XERCES_STD_QUALIFIER cout << "HexBinary"; break;
|
||||
case DatatypeValidator::Base64Binary: XERCES_STD_QUALIFIER cout << "Base64Binary";break;
|
||||
case DatatypeValidator::Duration: XERCES_STD_QUALIFIER cout << "Duration"; break;
|
||||
case DatatypeValidator::DateTime: XERCES_STD_QUALIFIER cout << "DateTime"; break;
|
||||
case DatatypeValidator::Date: XERCES_STD_QUALIFIER cout << "Date"; break;
|
||||
case DatatypeValidator::Time: XERCES_STD_QUALIFIER cout << "Time"; break;
|
||||
case DatatypeValidator::MonthDay: XERCES_STD_QUALIFIER cout << "MonthDay"; break;
|
||||
case DatatypeValidator::YearMonth: XERCES_STD_QUALIFIER cout << "YearMonth"; break;
|
||||
case DatatypeValidator::Year: XERCES_STD_QUALIFIER cout << "Year"; break;
|
||||
case DatatypeValidator::Month: XERCES_STD_QUALIFIER cout << "Month"; break;
|
||||
case DatatypeValidator::Day: XERCES_STD_QUALIFIER cout << "Day"; break;
|
||||
case DatatypeValidator::ID: XERCES_STD_QUALIFIER cout << "ID"; break;
|
||||
case DatatypeValidator::IDREF: XERCES_STD_QUALIFIER cout << "IDREF"; break;
|
||||
case DatatypeValidator::ENTITY: XERCES_STD_QUALIFIER cout << "ENTITY"; break;
|
||||
case DatatypeValidator::NOTATION: XERCES_STD_QUALIFIER cout << "NOTATION"; break;
|
||||
case DatatypeValidator::List: XERCES_STD_QUALIFIER cout << "List"; break;
|
||||
case DatatypeValidator::Union: XERCES_STD_QUALIFIER cout << "Union"; break;
|
||||
case DatatypeValidator::AnySimpleType: XERCES_STD_QUALIFIER cout << "AnySimpleType"; break;
|
||||
case DatatypeValidator::UnKnown: XERCES_STD_QUALIFIER cout << "UNKNOWN"; break;
|
||||
}
|
||||
|
||||
XERCES_STD_QUALIFIER cout << "\n";
|
||||
|
||||
// Facets
|
||||
RefHashTableOf<KVStringPair>* facets = dtValidator->getFacets();
|
||||
if( facets && facets->getCount()>0)
|
||||
{
|
||||
XMLSize_t i;
|
||||
// Element's properties
|
||||
XERCES_STD_QUALIFIER cout << "Facets:\t\t\n";
|
||||
// use a list to print them sorted, or the list could be different on 64-bit machines
|
||||
RefVectorOf<XMLCh> sortedList(facets->getCount(), false);
|
||||
RefHashTableOfEnumerator<KVStringPair> enumFacets(facets);
|
||||
while( enumFacets.hasMoreElements() )
|
||||
{
|
||||
const KVStringPair& curPair = enumFacets.nextElement();
|
||||
const XMLCh* key=curPair.getKey();
|
||||
XMLSize_t len=sortedList.size();
|
||||
for(i=0;i<len;i++)
|
||||
if(XMLString::compareString(key, sortedList.elementAt(i))<0)
|
||||
{
|
||||
sortedList.insertElementAt((XMLCh*)key,i);
|
||||
break;
|
||||
}
|
||||
if(i==len)
|
||||
sortedList.addElement((XMLCh*)key);
|
||||
}
|
||||
|
||||
XMLSize_t len=sortedList.size();
|
||||
for(i=0;i<len;i++)
|
||||
{
|
||||
const XMLCh* key = sortedList.elementAt(i);
|
||||
XERCES_STD_QUALIFIER cout << "\t" << StrX( key ) << "="
|
||||
<< StrX( facets->get(key)->getValue() ) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Enumerations
|
||||
RefVectorOf<XMLCh>* enums = (RefVectorOf<XMLCh>*) dtValidator->getEnumString();
|
||||
if (enums)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "Enumeration:\t\t\n";
|
||||
|
||||
int enumLength = enums->size();
|
||||
for ( int i = 0; i < enumLength; i++)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\t" << StrX( enums->elementAt(i)) << "\n";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void processContentSpecNode( const ContentSpecNode* cSpecNode, bool margin )
|
||||
{
|
||||
if( !cSpecNode )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if( margin )
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\t";
|
||||
}
|
||||
|
||||
XERCES_STD_QUALIFIER cout << "ContentType:\t";
|
||||
switch( cSpecNode->getType() )
|
||||
{
|
||||
case ContentSpecNode::Leaf: XERCES_STD_QUALIFIER cout << "Leaf"; break;
|
||||
case ContentSpecNode::ZeroOrOne: XERCES_STD_QUALIFIER cout << "ZeroOrOne"; break;
|
||||
case ContentSpecNode::ZeroOrMore: XERCES_STD_QUALIFIER cout << "ZeroOrMore"; break;
|
||||
case ContentSpecNode::OneOrMore: XERCES_STD_QUALIFIER cout << "OneOrMore"; break;
|
||||
case ContentSpecNode::Choice: XERCES_STD_QUALIFIER cout << "Choice"; break;
|
||||
case ContentSpecNode::Sequence: XERCES_STD_QUALIFIER cout << "Sequence"; break;
|
||||
case ContentSpecNode::All: XERCES_STD_QUALIFIER cout << "All"; break;
|
||||
case ContentSpecNode::Any: XERCES_STD_QUALIFIER cout << "Any"; break;
|
||||
case ContentSpecNode::Any_Other: XERCES_STD_QUALIFIER cout << "Any_Other"; break;
|
||||
case ContentSpecNode::Any_NS: XERCES_STD_QUALIFIER cout << "Any_NS"; break;
|
||||
case ContentSpecNode::Any_Lax: XERCES_STD_QUALIFIER cout << "Any_Lax"; break;
|
||||
case ContentSpecNode::Any_Other_Lax: XERCES_STD_QUALIFIER cout << "Any_Other_Lax"; break;
|
||||
case ContentSpecNode::Any_NS_Lax: XERCES_STD_QUALIFIER cout << "Any_NS_Lax"; break;
|
||||
case ContentSpecNode::Any_Skip: XERCES_STD_QUALIFIER cout << "Any_Skip"; break;
|
||||
case ContentSpecNode::Any_Other_Skip: XERCES_STD_QUALIFIER cout << "Any_Other_Skip"; break;
|
||||
case ContentSpecNode::Any_NS_Skip: XERCES_STD_QUALIFIER cout << "Any_NS_Skip"; break;
|
||||
case ContentSpecNode::Any_NS_Choice: XERCES_STD_QUALIFIER cout << "Any_NS_Choice"; break;
|
||||
case ContentSpecNode::ModelGroupSequence: XERCES_STD_QUALIFIER cout << "ModelGroupSequence"; break;
|
||||
case ContentSpecNode::ModelGroupChoice: XERCES_STD_QUALIFIER cout << "ModelGroupChoice"; break;
|
||||
case ContentSpecNode::UnknownType: XERCES_STD_QUALIFIER cout << "UnknownType"; break;
|
||||
}
|
||||
XERCES_STD_QUALIFIER cout << "\n";
|
||||
}
|
||||
|
||||
Executable
+227
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: StdInParse.cpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/StdInInputSource.hpp>
|
||||
#include <xercesc/parsers/SAXParser.hpp>
|
||||
#include "StdInParse.hpp"
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local data
|
||||
//
|
||||
// doNamespaces
|
||||
// Indicates whether namespace processing should be enabled or not.
|
||||
// The default is no, but -n overrides that.
|
||||
//
|
||||
// doSchema
|
||||
// Indicates whether schema processing should be enabled or not.
|
||||
// The default is no, but -s overrides that.
|
||||
//
|
||||
// schemaFullChecking
|
||||
// Indicates whether full schema constraint checking should be enabled or not.
|
||||
// The default is no, but -s overrides that.
|
||||
//
|
||||
// valScheme
|
||||
// Indicates what validation scheme to use. It defaults to 'auto', but
|
||||
// can be set via the -v= command.
|
||||
// ---------------------------------------------------------------------------
|
||||
static bool doNamespaces = false;
|
||||
static bool doSchema = false;
|
||||
static bool schemaFullChecking = false;
|
||||
static SAXParser::ValSchemes valScheme = SAXParser::Val_Auto;
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void usage()
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
||||
" StdInParse [options] < <XML file>\n\n"
|
||||
"This program demonstrates streaming XML data from standard\n"
|
||||
"input. It then uses the SAX Parser, and prints the\n"
|
||||
"number of elements, attributes, spaces and characters found\n"
|
||||
"in the input, using SAX API.\n\n"
|
||||
"Options:\n"
|
||||
" -v=xxx Validation scheme [always | never | auto*].\n"
|
||||
" -n Enable namespace processing. Defaults to off.\n"
|
||||
" -s Enable schema processing. Defaults to off.\n"
|
||||
" -f Enable full schema constraint checking. Defaults to off.\n"
|
||||
" -? Show this help.\n\n"
|
||||
" * = Default if not provided explicitly.\n"
|
||||
<< XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Program entry point
|
||||
// ---------------------------------------------------------------------------
|
||||
int main(int argC, char* argV[])
|
||||
{
|
||||
// Initialize the XML4C system
|
||||
try
|
||||
{
|
||||
XMLPlatformUtils::Initialize();
|
||||
}
|
||||
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
|
||||
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int parmInd;
|
||||
for (parmInd = 1; parmInd < argC; parmInd++)
|
||||
{
|
||||
// Break out on first parm not starting with a dash
|
||||
if (argV[parmInd][0] != '-')
|
||||
break;
|
||||
|
||||
// Watch for special case help request
|
||||
if (!strcmp(argV[parmInd], "-?"))
|
||||
{
|
||||
usage();
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
else if (!strncmp(argV[parmInd], "-v=", 3)
|
||||
|| !strncmp(argV[parmInd], "-V=", 3))
|
||||
{
|
||||
const char* const parm = &argV[parmInd][3];
|
||||
|
||||
if (!strcmp(parm, "never"))
|
||||
valScheme = SAXParser::Val_Never;
|
||||
else if (!strcmp(parm, "auto"))
|
||||
valScheme = SAXParser::Val_Auto;
|
||||
else if (!strcmp(parm, "always"))
|
||||
valScheme = SAXParser::Val_Always;
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown -v= value: " << parm << XERCES_STD_QUALIFIER endl;
|
||||
XMLPlatformUtils::Terminate();
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-n")
|
||||
|| !strcmp(argV[parmInd], "-N"))
|
||||
{
|
||||
doNamespaces = true;
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-s")
|
||||
|| !strcmp(argV[parmInd], "-S"))
|
||||
{
|
||||
doSchema = true;
|
||||
}
|
||||
else if (!strcmp(argV[parmInd], "-f")
|
||||
|| !strcmp(argV[parmInd], "-F"))
|
||||
{
|
||||
schemaFullChecking = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[parmInd]
|
||||
<< "', ignoring it\n" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Create a SAX parser object. Then, according to what we were told on
|
||||
// the command line, set the options.
|
||||
//
|
||||
SAXParser* parser = new SAXParser;
|
||||
parser->setValidationScheme(valScheme);
|
||||
parser->setDoNamespaces(doNamespaces);
|
||||
parser->setDoSchema(doSchema);
|
||||
parser->setValidationSchemaFullChecking(schemaFullChecking);
|
||||
|
||||
|
||||
//
|
||||
// Create our SAX handler object and install it on the parser, as the
|
||||
// document and error handler. We are responsible for cleaning them
|
||||
// up, but since its just stack based here, there's nothing special
|
||||
// to do.
|
||||
//
|
||||
StdInParseHandlers handler;
|
||||
parser->setDocumentHandler(&handler);
|
||||
parser->setErrorHandler(&handler);
|
||||
|
||||
unsigned long duration;
|
||||
int errorCount = 0;
|
||||
// create a faux scope so that 'src' destructor is called before
|
||||
// XMLPlatformUtils::Terminate
|
||||
{
|
||||
//
|
||||
// Kick off the parse and catch any exceptions. Create a standard
|
||||
// input input source and tell the parser to parse from that.
|
||||
//
|
||||
StdInInputSource src;
|
||||
try
|
||||
{
|
||||
const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
|
||||
parser->parse(src);
|
||||
const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
|
||||
duration = endMillis - startMillis;
|
||||
errorCount = parser->getErrorCount();
|
||||
}
|
||||
catch (const OutOfMemoryException&)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
|
||||
errorCount = 2;
|
||||
return 4;
|
||||
}
|
||||
catch (const XMLException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError during parsing: \n"
|
||||
<< StrX(e.getMessage())
|
||||
<< "\n" << XERCES_STD_QUALIFIER endl;
|
||||
errorCount = 1;
|
||||
return 4;
|
||||
}
|
||||
|
||||
// Print out the stats that we collected and time taken
|
||||
if (!errorCount) {
|
||||
XERCES_STD_QUALIFIER cout << StrX(src.getSystemId()) << ": " << duration << " ms ("
|
||||
<< handler.getElementCount() << " elems, "
|
||||
<< handler.getAttrCount() << " attrs, "
|
||||
<< handler.getSpaceCount() << " spaces, "
|
||||
<< handler.getCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Delete the parser itself. Must be done prior to calling Terminate, below.
|
||||
//
|
||||
delete parser;
|
||||
|
||||
XMLPlatformUtils::Terminate();
|
||||
|
||||
if (errorCount > 0)
|
||||
return 4;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: StdInParse.hpp 471735 2006-11-06 13:53:58Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes for all the program files to see
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include "StdInParseHandlers.hpp"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple class that lets us do easy (though not terribly efficient)
|
||||
// trancoding of XMLCh data to local code page for display.
|
||||
// ---------------------------------------------------------------------------
|
||||
class StrX
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StrX(const XMLCh* const toTranscode)
|
||||
{
|
||||
// Call the private transcoding method
|
||||
fLocalForm = XMLString::transcode(toTranscode);
|
||||
}
|
||||
|
||||
~StrX()
|
||||
{
|
||||
XMLString::release(&fLocalForm);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
const char* localForm() const
|
||||
{
|
||||
return fLocalForm;
|
||||
}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fLocalForm
|
||||
// This is the local code page form of the string.
|
||||
// -----------------------------------------------------------------------
|
||||
char* fLocalForm;
|
||||
};
|
||||
|
||||
inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
||||
{
|
||||
target << toDump.localForm();
|
||||
return target;
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: StdInParseHandlers.cpp 557282 2007-07-18 14:54:15Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/sax/AttributeList.hpp>
|
||||
#include <xercesc/sax/SAXParseException.hpp>
|
||||
#include <xercesc/sax/SAXException.hpp>
|
||||
#include "StdInParse.hpp"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// StdInParseHandlers: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
StdInParseHandlers::StdInParseHandlers() :
|
||||
|
||||
fAttrCount(0)
|
||||
, fCharacterCount(0)
|
||||
, fElementCount(0)
|
||||
, fSpaceCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
StdInParseHandlers::~StdInParseHandlers()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// StdInParseHandlers: Implementation of the SAX DocumentHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void StdInParseHandlers::endElement(const XMLCh* const /* name */)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
StdInParseHandlers::startElement( const XMLCh* const /* name */
|
||||
, AttributeList& attributes)
|
||||
{
|
||||
fElementCount++;
|
||||
fAttrCount += attributes.getLength();
|
||||
}
|
||||
|
||||
void StdInParseHandlers::characters(const XMLCh* const /* chars */
|
||||
, const XMLSize_t length)
|
||||
{
|
||||
fCharacterCount += length;
|
||||
}
|
||||
|
||||
void StdInParseHandlers::ignorableWhitespace(const XMLCh* const /* chars */
|
||||
, const XMLSize_t length)
|
||||
{
|
||||
fSpaceCount += length;
|
||||
}
|
||||
|
||||
void StdInParseHandlers::resetDocument()
|
||||
{
|
||||
fAttrCount = 0;
|
||||
fCharacterCount = 0;
|
||||
fElementCount = 0;
|
||||
fSpaceCount = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// StdInParseHandlers: Overrides of the SAX ErrorHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
void StdInParseHandlers::error(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError at (file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void StdInParseHandlers::fatalError(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nFatal Error at (file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
void StdInParseHandlers::warning(const SAXParseException& e)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nWarning at (file " << StrX(e.getSystemId())
|
||||
<< ", line " << e.getLineNumber()
|
||||
<< ", char " << e.getColumnNumber()
|
||||
<< "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: StdInParseHandlers.hpp 679377 2008-07-24 11:56:42Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/sax/HandlerBase.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
class AttributeList;
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
class StdInParseHandlers : public HandlerBase
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StdInParseHandlers();
|
||||
~StdInParseHandlers();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t getElementCount()
|
||||
{
|
||||
return fElementCount;
|
||||
}
|
||||
|
||||
XMLSize_t getAttrCount()
|
||||
{
|
||||
return fAttrCount;
|
||||
}
|
||||
|
||||
XMLSize_t getCharacterCount()
|
||||
{
|
||||
return fCharacterCount;
|
||||
}
|
||||
|
||||
XMLSize_t getSpaceCount()
|
||||
{
|
||||
return fSpaceCount;
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the SAX DocumentHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void endElement(const XMLCh* const name);
|
||||
void startElement(const XMLCh* const name, AttributeList& attributes);
|
||||
void characters(const XMLCh* const chars, const XMLSize_t length);
|
||||
void ignorableWhitespace(const XMLCh* const chars, const XMLSize_t length);
|
||||
void resetDocument();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Handlers for the SAX ErrorHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
void warning(const SAXParseException& exc);
|
||||
void error(const SAXParseException& exc);
|
||||
void fatalError(const SAXParseException& exc);
|
||||
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fAttrCount
|
||||
// fCharacterCount
|
||||
// fElementCount
|
||||
// fSpaceCount
|
||||
// These are just counters that are run upwards based on the input
|
||||
// from the document handlers.
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t fAttrCount;
|
||||
XMLSize_t fCharacterCount;
|
||||
XMLSize_t fElementCount;
|
||||
XMLSize_t fSpaceCount;
|
||||
};
|
||||
Executable
+234
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: XInclude.cpp 529303 2007-04-16 16:11:09Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/parsers/AbstractDOMParser.hpp>
|
||||
#include <xercesc/framework/LocalFileFormatTarget.hpp>
|
||||
#include <xercesc/dom/DOMDocument.hpp>
|
||||
#include <xercesc/dom/DOM.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
|
||||
#include "XInclude.hpp"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple program which tests the different XInclude mechanisms prototyped
|
||||
// for my dissertation. Based largely on the DOMCount example provided with the
|
||||
// Xerces C++ project.
|
||||
// Simon Rowland 2006
|
||||
// ---------------------------------------------------------------------------
|
||||
static void usage()
|
||||
{
|
||||
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
||||
" XInclude [-h] InputFile OutputFile\n"
|
||||
" -h : Prints this help message and exits.\n"
|
||||
<< XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// main
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
int main(int argC, char* argV[])
|
||||
{
|
||||
char *testFileName;
|
||||
char *outputFileName;
|
||||
|
||||
for (int argInd = 1; argInd < argC; argInd++)
|
||||
{
|
||||
if (!strcmp(argV[argInd], "-?") || !strcmp(argV[argInd], "-h"))
|
||||
{
|
||||
/* print help and exit */
|
||||
usage();
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (argC < 3){
|
||||
usage();
|
||||
return 2;
|
||||
}
|
||||
|
||||
testFileName = argV[argC-2];
|
||||
outputFileName = argV[argC-1];
|
||||
|
||||
// Initialize the XML4C system
|
||||
try
|
||||
{
|
||||
XMLPlatformUtils::Initialize();
|
||||
}
|
||||
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "Error during initialization! :\n"
|
||||
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
// Instantiate the DOM parser to use for the source documents
|
||||
//============================================================================
|
||||
static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
|
||||
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(gLS);
|
||||
DOMLSParser *parser = ((DOMImplementationLS*)impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
|
||||
DOMConfiguration *config = parser->getDomConfig();
|
||||
|
||||
config->setParameter(XMLUni::fgDOMNamespaces, true);
|
||||
config->setParameter(XMLUni::fgXercesSchema, true);
|
||||
config->setParameter(XMLUni::fgXercesSchemaFullChecking, true);
|
||||
|
||||
if(config->canSetParameter(XMLUni::fgXercesDoXInclude, true)){
|
||||
config->setParameter(XMLUni::fgXercesDoXInclude, true);
|
||||
}
|
||||
|
||||
// enable datatype normalization - default is off
|
||||
//config->setParameter(XMLUni::fgDOMDatatypeNormalization, true);
|
||||
|
||||
// And create our error handler and install it
|
||||
XIncludeErrorHandler errorHandler;
|
||||
config->setParameter(XMLUni::fgDOMErrorHandler, &errorHandler);
|
||||
|
||||
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc = 0;
|
||||
|
||||
try
|
||||
{
|
||||
// load up the test source document
|
||||
XERCES_STD_QUALIFIER cerr << "Parse " << testFileName << " in progress ...";
|
||||
parser->resetDocumentPool();
|
||||
doc = parser->parseURI(testFileName);
|
||||
XERCES_STD_QUALIFIER cerr << " finished." << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << testFileName << "'\n"
|
||||
<< "Exception message is: \n"
|
||||
<< StrX(toCatch.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
catch (const DOMException& toCatch)
|
||||
{
|
||||
const unsigned int maxChars = 2047;
|
||||
XMLCh errText[maxChars + 1];
|
||||
|
||||
XERCES_STD_QUALIFIER cerr << "\nDOM Error during parsing: '" << testFileName << "'\n"
|
||||
<< "DOMException code is: " << toCatch.code << XERCES_STD_QUALIFIER endl;
|
||||
|
||||
if (DOMImplementation::loadDOMExceptionMsg(toCatch.code, errText, maxChars))
|
||||
XERCES_STD_QUALIFIER cerr << "Message is: " << StrX(errText) << XERCES_STD_QUALIFIER endl;
|
||||
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nUnexpected exception during parsing: '" << testFileName << "'\n";
|
||||
}
|
||||
|
||||
if (!errorHandler.getSawErrors() && doc) {
|
||||
DOMLSSerializer *writer = ((DOMImplementationLS*)impl)->createLSSerializer();
|
||||
DOMLSOutput *theOutputDesc = ((DOMImplementationLS*)impl)->createLSOutput();
|
||||
|
||||
try {
|
||||
// write out the results
|
||||
XERCES_STD_QUALIFIER cerr << "Writing result to: " << outputFileName << XERCES_STD_QUALIFIER endl;
|
||||
|
||||
XMLFormatTarget *myFormTarget = new LocalFileFormatTarget(outputFileName);
|
||||
theOutputDesc->setByteStream(myFormTarget);
|
||||
writer->write(doc, theOutputDesc);
|
||||
delete myFormTarget;
|
||||
}
|
||||
catch (const XMLException& toCatch)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nXMLException during writing: '" << testFileName << "'\n"
|
||||
<< "Exception message is: \n"
|
||||
<< StrX(toCatch.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
catch (const DOMException& toCatch)
|
||||
{
|
||||
const unsigned int maxChars = 2047;
|
||||
XMLCh errText[maxChars + 1];
|
||||
|
||||
XERCES_STD_QUALIFIER cerr << "\nDOM Error during writing: '" << testFileName << "'\n"
|
||||
<< "DOMException code is: " << toCatch.code << XERCES_STD_QUALIFIER endl;
|
||||
|
||||
if (DOMImplementation::loadDOMExceptionMsg(toCatch.code, errText, maxChars))
|
||||
XERCES_STD_QUALIFIER cerr << "Message is: " << StrX(errText) << XERCES_STD_QUALIFIER endl;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nUnexpected exception during writing: '" << testFileName << "'\n";
|
||||
}
|
||||
writer->release();
|
||||
theOutputDesc->release();
|
||||
}
|
||||
|
||||
//
|
||||
// Delete the parser itself. Must be done prior to calling Terminate, below.
|
||||
//
|
||||
parser->release();
|
||||
// And call the termination method
|
||||
XMLPlatformUtils::Terminate();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
XIncludeErrorHandler::XIncludeErrorHandler() :
|
||||
fSawErrors(false)
|
||||
{
|
||||
}
|
||||
|
||||
XIncludeErrorHandler::~XIncludeErrorHandler()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XIncludeHandlers: Overrides of the DOM ErrorHandler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
bool XIncludeErrorHandler::handleError(const DOMError& domError)
|
||||
{
|
||||
bool continueParsing = true;
|
||||
if (domError.getSeverity() == DOMError::DOM_SEVERITY_WARNING)
|
||||
XERCES_STD_QUALIFIER cerr << "\nWarning at file ";
|
||||
else if (domError.getSeverity() == DOMError::DOM_SEVERITY_ERROR)
|
||||
{
|
||||
XERCES_STD_QUALIFIER cerr << "\nError at file ";
|
||||
fSawErrors = true;
|
||||
}
|
||||
else {
|
||||
XERCES_STD_QUALIFIER cerr << "\nFatal Error at file ";
|
||||
continueParsing = false;
|
||||
fSawErrors = true;
|
||||
}
|
||||
|
||||
XERCES_STD_QUALIFIER cerr << StrX(domError.getLocation()->getURI())
|
||||
<< ", line " << domError.getLocation()->getLineNumber()
|
||||
<< ", char " << domError.getLocation()->getColumnNumber()
|
||||
<< "\n Message: " << StrX(domError.getMessage()) << XERCES_STD_QUALIFIER endl;
|
||||
|
||||
return continueParsing;
|
||||
}
|
||||
|
||||
void XIncludeErrorHandler::resetErrors()
|
||||
{
|
||||
fSawErrors = false;
|
||||
}
|
||||
|
||||
Executable
+131
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: XInclude.hpp 513675 2007-03-02 09:22:55Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/dom/DOMErrorHandler.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
|
||||
#if defined(XERCES_NEW_IOSTREAMS)
|
||||
#include <iostream>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
|
||||
XERCES_CPP_NAMESPACE_USE
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Simple error handler deriviative to install on parser
|
||||
// ---------------------------------------------------------------------------
|
||||
class XIncludeErrorHandler : public DOMErrorHandler
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
XIncludeErrorHandler();
|
||||
~XIncludeErrorHandler();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
bool getSawErrors() const;
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementation of the DOM ErrorHandler interface
|
||||
// -----------------------------------------------------------------------
|
||||
bool handleError(const DOMError& domError);
|
||||
void resetErrors();
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XIncludeErrorHandler(const XIncludeErrorHandler&);
|
||||
void operator=(const XIncludeErrorHandler&);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fSawErrors
|
||||
// This is set if we get any errors, and is queryable via a getter
|
||||
// method. Its used by the main code to suppress output if there are
|
||||
// errors.
|
||||
// -----------------------------------------------------------------------
|
||||
bool fSawErrors;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is a simple class that lets us do easy (though not terribly efficient)
|
||||
// trancoding of XMLCh data to local code page for display.
|
||||
// ---------------------------------------------------------------------------
|
||||
class StrX
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StrX(const XMLCh* const toTranscode)
|
||||
{
|
||||
// Call the private transcoding method
|
||||
fLocalForm = XMLString::transcode(toTranscode);
|
||||
}
|
||||
|
||||
~StrX()
|
||||
{
|
||||
XMLString::release(&fLocalForm);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
const char* localForm() const
|
||||
{
|
||||
return fLocalForm;
|
||||
}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fLocalForm
|
||||
// This is the local code page form of the string.
|
||||
// -----------------------------------------------------------------------
|
||||
char* fLocalForm;
|
||||
};
|
||||
|
||||
inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
||||
{
|
||||
target << toDump.localForm();
|
||||
return target;
|
||||
}
|
||||
|
||||
inline bool XIncludeErrorHandler::getSawErrors() const
|
||||
{
|
||||
return fSawErrors;
|
||||
}
|
||||
Reference in New Issue
Block a user