diff --git a/Projects/Win32/VC6/xerces-all/SCMPrint/SCMPrint.dsp b/Projects/Win32/VC6/xerces-all/SCMPrint/SCMPrint.dsp new file mode 100644 index 0000000000000000000000000000000000000000..15a5dd75b7f8c6ed525dc7f674a00442713e591a --- /dev/null +++ b/Projects/Win32/VC6/xerces-all/SCMPrint/SCMPrint.dsp @@ -0,0 +1,143 @@ +# Microsoft Developer Studio Project File - Name="SCMPrint" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=SCMPrint - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "SCMPrint.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "SCMPrint.mak" CFG="SCMPrint - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "SCMPrint - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "SCMPrint - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "SCMPrint - Win64 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "SCMPrint - Win64 Release" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "SCMPrint - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\..\..\..\..\Build\Win32\VC6\Release" +# PROP Intermediate_Dir "..\..\..\..\..\Build\Win32\VC6\Release\obj" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /G6 /MD /W3 /GX /O2 /Ob2 /I "..\..\..\..\..\src" /D "NDEBUG" /D "_CONSOLE" /D "WIN32" /D "_WINDOWS" /D "PLATFORM_WIN32" /FD /c +# SUBTRACT CPP /Fr /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib xerces-c_2.lib /subsystem:console /incremental:yes /machine:I386 /libpath:"..\..\..\..\..\Build\Win32\VC6\Release" + +!ELSEIF "$(CFG)" == "SCMPrint - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "..\..\..\..\..\Build\Win32\VC6\Debug" +# PROP Intermediate_Dir "..\..\..\..\..\Build\Win32\VC6\Debug\obj" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /G6 /MDd /Za /W3 /Gm /GX /ZI /Od /I "..\..\..\..\..\src" /D "_CONSOLE" /D "PLATFORM_WIN32" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib xerces-c_2D.lib /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\..\..\Build\Win32\VC6\Debug" + +!ELSEIF "$(CFG)" == "SCMPrint - Win64 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "..\..\..\..\..\Build\Win64\VC6\Debug" +# PROP Intermediate_Dir "..\..\..\..\..\Build\Win64\VC6\Debug\obj" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /G6 /MDd /Za /W3 /Gm /GX /ZI /Od /I "..\..\..\..\..\src" /D "_DEBUG" /D "_CONSOLE" /D "WIN32" /D "_WINDOWS" /D "PLATFORM_WIN32" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /MDd /W3 /Gm /GX /ZI /Od /I "..\..\..\..\..\src" /D "WIN64" /D "_DEBUG" /D "_CONSOLE" /D "WIN32" /D "_WINDOWS" /D "PLATFORM_WIN32" /FD /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib xerces-c_2D.lib /subsystem:console /debug /machine:IX86 /pdbtype:sept /libpath:"..\..\..\..\..\Build\Win32\VC6\Debug" +# ADD LINK32 kernel32.lib user32.lib xerces-c_2D.lib /subsystem:console /debug /machine:IX86 /pdbtype:sept /libpath:"..\..\..\..\..\Build\Win64\VC6\Debug" /machine:IA64 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "SCMPrint - Win64 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\..\..\..\..\Build\Win64\VC6\Release" +# PROP Intermediate_Dir "..\..\..\..\..\Build\Win64\VC6\Release\obj" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /G6 /MD /W3 /GX /O2 /Ob2 /I "..\..\..\..\..\src" /D "NDEBUG" /D "_CONSOLE" /D "WIN32" /D "_WINDOWS" /D "PLATFORM_WIN32" /FR /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /MD /W3 /GX /O2 /Ob2 /I "..\..\..\..\..\src" /D "WIN64" /D "NDEBUG" /D "_CONSOLE" /D "WIN32" /D "_WINDOWS" /D "PLATFORM_WIN32" /FD /c +# SUBTRACT CPP /Fr +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib xerces-c_2.lib /subsystem:console /incremental:yes /machine:IX86 /libpath:"..\..\..\..\..\Build\Win32\VC6\Release" +# ADD LINK32 kernel32.lib user32.lib xerces-c_2.lib /subsystem:console /incremental:yes /machine:IX86 /libpath:"..\..\..\..\..\Build\Win64\VC6\Release" /machine:IA64 +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "SCMPrint - Win32 Release" +# Name "SCMPrint - Win32 Debug" +# Name "SCMPrint - Win64 Debug" +# Name "SCMPrint - Win64 Release" +# Begin Source File + +SOURCE=..\..\..\..\..\samples\SCMPrint\SCMPrint.cpp +# End Source File +# End Target +# End Project diff --git a/Projects/Win32/VC6/xerces-all/xerces-all.dsw b/Projects/Win32/VC6/xerces-all/xerces-all.dsw index 84640f7209d735c94d1a95b60197eb609b8ea20f..ee01395da3f6fc79bc25331d1cf587c184c3b015 100644 --- a/Projects/Win32/VC6/xerces-all/xerces-all.dsw +++ b/Projects/Win32/VC6/xerces-all/xerces-all.dsw @@ -333,6 +333,21 @@ Package=<4> ############################################################################### +Project: "SCMPrint"=".\SCMPrint\SCMPrint.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name XercesLib + End Project Dependency +}}} + +############################################################################### + Project: "SEnumVal"=".\SEnumVal\SEnumVal.dsp" - Package Owner=<4> Package=<5> @@ -494,6 +509,9 @@ Package=<4> Begin Project Dependency Project_Dep_Name PSVIWriter End Project Dependency + Begin Project Dependency + Project_Dep_Name SCMPrint + End Project Dependency }}} ############################################################################### diff --git a/samples/SCMPrint/SCMPrint.cpp b/samples/SCMPrint/SCMPrint.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0150e7ff42bde47944fe26406983a0106852d89a --- /dev/null +++ b/samples/SCMPrint/SCMPrint.cpp @@ -0,0 +1,503 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2004 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Xerces" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache\@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation, and was + * originally based on software copyright (c) 1999, International + * Business Machines, Inc., http://www.ibm.com . For more information + * on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ + +/* + * $Log$ + * Revision 1.1 2004/02/11 20:53:05 peiyongz + * SCMPrint + * + */ + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <xercesc/util/PlatformUtils.hpp> +#include <xercesc/sax2/SAX2XMLReader.hpp> +#include <xercesc/sax2/XMLReaderFactory.hpp> +#include <xercesc/internal/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 <fstream> +#else +#include <fstream.h> +#endif +#include <stdlib.h> +#include <string.h> + + +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; +} + +// --------------------------------------------------------------------------- +// 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; + } + + try + { + XMLGrammarPool *grammarPool = new XMLGrammarPoolImpl(XMLPlatformUtils::fgMemoryManager); + + SAX2XMLReaderImpl* parser = new SAX2XMLReaderImpl(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); + + + 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 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); + } + + XERCES_STD_QUALIFIER cout << "********** Printing out information from Schema **********" << "\n\n"; + + XSModel *xsModel = grammarPool->getXSModel(); + 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 && (XMLString::stringLen(nameSpace)>0)) + 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"; + } + XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl; + } + 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; + } + + 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 && (XMLString::stringLen(nameSpace)>0)) { + 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 (unsigned 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) +{ + 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 (unsigned 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; + } +}