void XSDParser::ParseHeader() { // xml header TToken tok = GetNextToken(); if (tok == K_XML) { for ( ; tok != K_ENDOFTAG; tok=GetNextToken()) ; tok = GetNextToken(); } else { if (m_SrcType == eSchema) { ERR_POST_X(4, "LINE " << Location() << " XML declaration is missing"); } } // schema if (tok != K_SCHEMA) { ParseError("Unexpected token", "schema"); } m_EnableNamespaceRedefinition = true; for ( tok = GetNextToken(); tok == K_ATTPAIR || tok == K_XMLNS; tok = GetNextToken()) { if (tok == K_ATTPAIR) { if (IsAttribute("targetNamespace")) { m_TargetNamespace = m_Value; } else if (IsAttribute("elementFormDefault")) { m_ElementFormDefault = IsValue("qualified"); } else if (IsAttribute("attributeFormDefault")) { m_AttributeFormDefault = IsValue("qualified"); } } } m_EnableNamespaceRedefinition = false; if (tok != K_CLOSING) { ParseError("tag closing"); } }
void XSDParser::ParseImport(void) { TToken tok = GetRawAttributeSet(); if (GetAttribute("namespace")) { if (IsValue("http://www.w3.org/XML/1998/namespace") || (IsValue("//www.w3.org/XML/1998/namespace") && m_ValuePrefix == "http")) { string name = "xml:lang"; m_MapAttribute[name].SetName(name); m_MapAttribute[name].SetType(DTDAttribute::eString); } } if (tok == K_CLOSING) { SkipContent(); } }
void XSDParser::ParseAttribute(DTDElement& node) { DTDAttribute a; node.AddAttribute(a); DTDAttribute& att = node.GetNonconstAttributes().back(); att.SetSourceLine(Lexer().CurrentLine()); SetCommentsIfEmpty(&(att.Comments())); bool ref=false, named_type=false; bool qualified = m_AttributeFormDefault; TToken tok = GetRawAttributeSet(); if (GetAttribute("ref")) { att.SetName(m_Value); ref=true; } if (GetAttribute("name")) { att.SetName(m_Value); } if (GetAttribute("type")) { if (!DefineAttributeType(att)) { att.SetTypeName(m_Value); named_type = true; } } if (GetAttribute("use")) { if (IsValue("required")) { att.SetValueType(DTDAttribute::eRequired); } else if (IsValue("optional")) { att.SetValueType(DTDAttribute::eImplied); } else if (IsValue("prohibited")) { att.SetValueType(DTDAttribute::eProhibited); } } if (GetAttribute("default")) { att.SetValue(m_Value); } if (GetAttribute("form")) { qualified = IsValue("qualified"); } att.SetQualified(qualified); if (tok == K_CLOSING) { ParseContent(att); } if (!ref && !named_type) { att.SetTypeIfUnknown(DTDAttribute::eString); } m_ExpectLastComment = true; }
const Value &Node::AsValue() const { if (IsValue()) return static_cast<const Value&>(*this); else throw TypeException(); }
void XSDParser::ParseAny(DTDElement& node) { TToken tok = GetRawAttributeSet(); #if 0 if (GetAttribute("processContents")) { if (!IsValue("lax") && !IsValue("skip")) { ParseError("lax or skip"); } } #endif node.SetOccurrence( ParseMinOccurs( node.GetOccurrence())); node.SetOccurrence( ParseMaxOccurs( node.GetOccurrence())); if (GetAttribute("namespace")) { node.SetNamespaceName(m_Value); } SetCommentsIfEmpty(&(node.Comments())); if (tok == K_CLOSING) { ParseContent(node); } m_ExpectLastComment = true; }
void XSDParser::ParseComplexType(DTDElement& node) { TToken tok = GetRawAttributeSet(); if (GetAttribute("mixed")) { if (IsValue("true")) { string name(s_SpecialName); AddElementContent(node,name); } } if (tok == K_CLOSING) { ParseContent(node); } }
DTDElement::EOccurrence XSDParser::ParseMaxOccurs( DTDElement::EOccurrence occNow) { DTDElement::EOccurrence occNew = occNow; if (GetAttribute("maxOccurs")) { int m = IsValue("unbounded") ? -1 : NStr::StringToInt(m_Value); if (m == -1 || m > 1) { if (m > 1) { ERR_POST_X(8, Warning << "Unsupported element maxOccurs= " << m); } if (occNow == DTDElement::eOne) { occNew = DTDElement::eOneOrMore; } else if (occNow == DTDElement::eZeroOrOne) { occNew = DTDElement::eZeroOrMore; } } else if (m == 0) { occNew = DTDElement::eZero; } } return occNew; }
string XSDParser::ParseElementContent(DTDElement* owner, int emb) { TToken tok; string name, value; bool ref=false, named_type=false; bool qualified = m_ElementFormDefault; int line = Lexer().CurrentLine(); tok = GetRawAttributeSet(); if (GetAttribute("ref")) { if (IsValue("schema") && GetElementNamespace(m_ValuePrefix) == eSchemaNamespace) { name = CreateTmpEmbeddedName(owner->GetName(), emb); DTDElement& elem = m_MapElement[name]; elem.SetName(m_Value); elem.SetSourceLine(Lexer().CurrentLine()); elem.SetEmbedded(); elem.SetType(DTDElement::eAny); ref=false; } else { name = m_Value; ref=true; } } if (GetAttribute("name")) { ref=false; name = m_Value; if (owner) { name = CreateTmpEmbeddedName(owner->GetName(), emb); m_MapElement[name].SetEmbedded(); m_MapElement[name].SetNamed(); } m_MapElement[name].SetName(m_Value); m_MapElement[name].SetSourceLine(line); SetCommentsIfEmpty(&(m_MapElement[name].Comments())); } if (GetAttribute("type")) { if (!DefineElementType(m_MapElement[name])) { m_MapElement[name].SetTypeName(m_Value); named_type = true; } } if (owner && GetAttribute("form")) { qualified = IsValue("qualified"); } if (GetAttribute("default")) { m_MapElement[name].SetDefault(m_Value); } if (owner && !name.empty()) { owner->SetOccurrence(name, ParseMinOccurs( owner->GetOccurrence(name))); owner->SetOccurrence(name, ParseMaxOccurs( owner->GetOccurrence(name))); } if (tok != K_CLOSING && tok != K_ENDOFTAG) { ParseError("endoftag"); } m_MapElement[name].SetNamespaceName(m_TargetNamespace); m_MapElement[name].SetQualified(qualified); bool hasContents = false; if (tok == K_CLOSING) { hasContents = ParseContent(m_MapElement[name]); } m_ExpectLastComment = true; if (!ref && !named_type) { m_MapElement[name].SetTypeIfUnknown( hasContents ? DTDElement::eEmpty : DTDElement::eString); } return name; }
bool XSDParser::DefineAttributeType(DTDAttribute& attrib) { if (IsValue("string") || IsValue("token") || IsValue("QName") || IsValue("anyURI") || IsValue("dateTime") || IsValue("time") || IsValue("date")) { attrib.SetType(DTDAttribute::eString); } else if (IsValue("ID")) { attrib.SetType(DTDAttribute::eId); } else if (IsValue("IDREF")) { attrib.SetType(DTDAttribute::eIdRef); } else if (IsValue("IDREFS")) { attrib.SetType(DTDAttribute::eIdRefs); } else if (IsValue("NMTOKEN")) { attrib.SetType(DTDAttribute::eNmtoken); } else if (IsValue("NMTOKENS")) { attrib.SetType(DTDAttribute::eNmtokens); } else if (IsValue("ENTITY")) { attrib.SetType(DTDAttribute::eEntity); } else if (IsValue("ENTITIES")) { attrib.SetType(DTDAttribute::eEntities); } else if (IsValue("boolean")) { attrib.SetType(DTDAttribute::eBoolean); } else if (IsValue("int") || IsValue("integer") || IsValue("short") || IsValue("byte") || IsValue("negativeInteger") || IsValue("nonNegativeInteger") || IsValue("positiveInteger") || IsValue("nonPositiveInteger") || IsValue("unsignedInt") || IsValue("unsignedShort") || IsValue("unsignedByte") ) { attrib.SetType(DTDAttribute::eInteger); } else if (IsValue("long") || IsValue("unsignedLong")) { attrib.SetType(DTDAttribute::eBigInt); } else if (IsValue("float") || IsValue("double") || IsValue("decimal")) { attrib.SetType(DTDAttribute::eDouble); } else if (IsValue("base64Binary")) { attrib.SetType(DTDAttribute::eBase64Binary); } else { return false; } return true; }
bool XSDParser::DefineElementType(DTDElement& node) { if (IsValue("string") || IsValue("token") || IsValue("normalizedString") || IsValue("anyURI") || IsValue("QName") || IsValue("dateTime") || IsValue("time") || IsValue("date") || IsValue("anySimpleType")) { node.SetType(DTDElement::eString); } else if (IsValue("double") || IsValue("float") || IsValue("decimal")) { node.SetType(DTDElement::eDouble); } else if (IsValue("boolean")) { node.SetType(DTDElement::eBoolean); } else if (IsValue("integer") || IsValue("int") || IsValue("short") || IsValue("byte") || IsValue("negativeInteger") || IsValue("nonNegativeInteger") || IsValue("positiveInteger") || IsValue("nonPositiveInteger") || IsValue("unsignedInt") || IsValue("unsignedShort") || IsValue("unsignedByte") ) { node.SetType(DTDElement::eInteger); } else if (IsValue("long") || IsValue("unsignedLong")) { node.SetType(DTDElement::eBigInt); } else if (IsValue("hexBinary")) { node.SetType(DTDElement::eOctetString); } else if (IsValue("base64Binary")) { node.SetType(DTDElement::eBase64Binary); } else { return false; } return true; }