1 #ifndef XSDPARSER_HPP 2 #define XSDPARSER_HPP 3 4 /* $Id: xsdparser.hpp 547822 2017-10-04 15:45:27Z gouriano $ 5 * =========================================================================== 6 * 7 * PUBLIC DOMAIN NOTICE 8 * National Center for Biotechnology Information 9 * 10 * This software/database is a "United States Government Work" under the 11 * terms of the United States Copyright Act. It was written as part of 12 * the author's official duties as a United States Government employee and 13 * thus cannot be copyrighted. This software/database is freely available 14 * to the public for use. The National Library of Medicine and the U.S. 15 * Government have not placed any restriction on its use or reproduction. 16 * 17 * Although all reasonable efforts have been taken to ensure the accuracy 18 * and reliability of the software and data, the NLM and the U.S. 19 * Government do not and cannot warrant the performance or results that 20 * may be obtained by using this software or data. The NLM and the U.S. 21 * Government disclaim all warranties, express or implied, including 22 * warranties of performance, merchantability or fitness for any particular 23 * purpose. 24 * 25 * Please cite the author in any work or product based on this material. 26 * 27 * =========================================================================== 28 * 29 * Author: Andrei Gourianov 30 * 31 * File Description: 32 * XML Schema parser 33 * 34 * =========================================================================== 35 */ 36 37 #include <corelib/ncbiutil.hpp> 38 #include "dtdparser.hpp" 39 #include "xsdlexer.hpp" 40 41 BEGIN_NCBI_SCOPE 42 43 44 ///////////////////////////////////////////////////////////////////////////// 45 // XSDParser 46 47 class XSDParser : public DTDParser 48 { 49 public: 50 XSDParser( XSDLexer& lexer); 51 virtual ~XSDParser(void); 52 53 enum EElementNamespace { 54 eUnknownNamespace, 55 eSchemaNamespace, 56 eWsdlNamespace, 57 eSoapNamespace 58 }; 59 60 protected: 61 virtual void BeginDocumentTree(void) override; 62 virtual void BuildDocumentTree(CDataTypeModule& module) override; 63 void Reset(void); 64 TToken GetNextToken(void); 65 66 EElementNamespace GetElementNamespace(const string& prefix); 67 bool IsAttribute(const char* att) const; 68 bool IsValue(const char* value) const; 69 bool DefineElementType(DTDElement& node); 70 bool DefineAttributeType(DTDAttribute& att); 71 72 void ParseHeader(void); 73 void ParseInclude(void); 74 void ParseImport(void); 75 void ParseAnnotation(void); 76 void ParseDocumentation(void); 77 void ParseAppInfo(void); 78 79 TToken GetRawAttributeSet(void); 80 bool GetAttribute(const string& att); 81 82 void SkipContent(); 83 84 DTDElement::EOccurrence ParseMinOccurs( DTDElement& node, DTDElement::EOccurrence occNow); 85 DTDElement::EOccurrence ParseMaxOccurs( DTDElement& node, DTDElement::EOccurrence occNow); 86 87 string ParseElementContent(DTDElement* owner, int emb); 88 string ParseGroup(DTDElement* owner, int emb); 89 void ParseGroupRef(DTDElement& node); 90 bool ParseContent(DTDElement& node, bool extended=false); 91 void ParseContainer(DTDElement& node); 92 93 void ParseComplexType(DTDElement& node); 94 void ParseSimpleType(DTDElement& node); 95 void ParseSimpleContent(DTDElement& node); 96 void ParseExtension(DTDElement& node); 97 void ParseRestriction(DTDElement& node); 98 void ParseFacet(DTDElement& node, TToken tok); 99 void ParseEnumeration(DTDElement& node); 100 void ParseAttribute(DTDElement& node); 101 void ParseAttributeGroup(DTDElement& node); 102 void ParseAttributeGroupRef(DTDElement& node); 103 104 void ParseAny(DTDElement& node); 105 void ParseUnion(DTDElement& node); 106 void ParseList(DTDElement& node); 107 108 string ParseAttributeContent(void); 109 void ParseContent(DTDAttribute& att); 110 void ParseExtension(DTDAttribute& att); 111 void ParseRestriction(DTDAttribute& att); 112 void ParseEnumeration(DTDAttribute& att); 113 void ParseUnion(DTDAttribute& att); 114 void ParseList(DTDAttribute& att); 115 116 string CreateTmpEmbeddedName(const string& name, int emb); 117 string CreateEntityId( const string& name,DTDEntity::EType type, 118 const string* prefix=NULL); 119 void CreateTypeDefinition(DTDEntity::EType type); 120 void ParseTypeDefinition(DTDEntity& ent); 121 void ProcessNamedTypes(void); 122 123 void BeginScope(DTDEntity* ent); 124 void EndScope(void); 125 virtual DTDEntity* PushEntityLexer(const string& name) override; 126 virtual bool PopEntityLexer(void) override; 127 virtual AbstractLexer* CreateEntityLexer( 128 CNcbiIstream& in, const string& name, bool autoDelete=true) override; 129 130 #if defined(NCBI_DTDPARSER_TRACE) 131 virtual void PrintDocumentTree(void); 132 #endif 133 134 protected: 135 string m_Raw; 136 string m_Element; 137 string m_ElementPrefix; 138 string m_Attribute; 139 string m_AttributePrefix; 140 string m_Value; 141 string m_ValuePrefix; 142 143 map<string, pair< string,string > > m_RawAttributes; 144 145 map<string,string> m_PrefixToNamespace; 146 map<string,string> m_NamespaceToPrefix; 147 map<string,DTDAttribute> m_MapAttribute; 148 string m_TargetNamespace; 149 bool m_ElementFormDefault; 150 bool m_AttributeFormDefault; 151 152 private: 153 stack< map<string,string> > m_StackPrefixToNamespace; 154 stack< map<string,string> > m_StackNamespaceToPrefix; 155 stack<string> m_StackTargetNamespace; 156 stack<bool> m_StackElementFormDefault; 157 stack<bool> m_StackAttributeFormDefault; 158 set<string> m_EmbeddedNames; 159 bool m_ResolveTypes; 160 bool m_EnableNamespaceRedefinition; 161 }; 162 163 END_NCBI_SCOPE 164 165 #endif // XSDPARSER_HPP 166