/// <summary> /// Call handler for the current element /// </summary> /// <param name="reader">XmlReader positioned at the element</param> /// <returns>true if element content should be skipped</returns> private bool ParseElement(XmlReader reader) { string elementNamespace = reader.NamespaceURI; // for schema element that right under the schema, we just ignore them, since schema does not // have metadataproperties if (!Schema.IsParseableXmlNamespace(elementNamespace, true) && this.ParentElement != null) { return(AddOtherContent(reader)); } if (HandleElement(reader)) { return(false); } else { // we need to report an error if the namespace for this element is a target namespace for the xml schemas we are parsing against. // otherwise we assume that this is either a valid 'any' element or that the xsd validator has generated an error if (string.IsNullOrEmpty(elementNamespace) || Schema.IsParseableXmlNamespace(reader.NamespaceURI, false)) { AddError(ErrorCode.UnexpectedXmlElement, EdmSchemaErrorSeverity.Error, reader, System.Data.Entity.Strings.UnexpectedXmlElement(reader.Name)); } return(true); } }
/// <summary> /// Call handler for the current attribute /// </summary> /// <param name="reader">XmlReader positioned at the attribute</param> private void ParseAttribute(XmlReader reader) { #if false // the attribute value is schema invalid, just skip it; this avoids some duplicate errors at the expense of better error messages... if (reader.SchemaInfo != null && reader.SchemaInfo.Validity == System.Xml.Schema.XmlSchemaValidity.Invalid) { continue; } #endif string attributeNamespace = reader.NamespaceURI; if (attributeNamespace == XmlConstants.AnnotationNamespace && reader.LocalName == XmlConstants.UseStrongSpatialTypes && !ProhibitAttribute(attributeNamespace, reader.LocalName) && HandleAttribute(reader)) { return; } else if (!Schema.IsParseableXmlNamespace(attributeNamespace, true)) { AddOtherContent(reader); } else if (!ProhibitAttribute(attributeNamespace, reader.LocalName) && HandleAttribute(reader)) { return; } else if (reader.SchemaInfo == null || reader.SchemaInfo.Validity != System.Xml.Schema.XmlSchemaValidity.Invalid) { // there's no handler for (namespace,name) and there wasn't a validation error. // Report an error of our own if the node is in no namespace or if it is in one of our xml schemas tartget namespace. if (string.IsNullOrEmpty(attributeNamespace) || Schema.IsParseableXmlNamespace(attributeNamespace, true)) { AddError(ErrorCode.UnexpectedXmlAttribute, EdmSchemaErrorSeverity.Error, reader, System.Data.Entity.Strings.UnexpectedXmlAttribute(reader.Name)); } } }
private bool AddOtherContent(XmlReader reader) { int lineNumber; int linePosition; GetPositionInfo(reader, out lineNumber, out linePosition); MetadataProperty property; if (reader.NodeType == XmlNodeType.Element) { if (this._schema.SchemaVersion == XmlConstants.EdmVersionForV1 || this._schema.SchemaVersion == XmlConstants.EdmVersionForV1_1) { // skip this element // we don't support element annotations in v1 and v1.1 return(true); } // in V1 and V1.1 the codegen can only appear as the attribute annotation and we want to maintain // the same behavior for V2, thus we throw if we encounter CodeGen namespace // in structural annotation in V2 and furthur version if (this._schema.SchemaVersion >= XmlConstants.EdmVersionForV2 && reader.NamespaceURI == XmlConstants.CodeGenerationSchemaNamespace) { Debug.Assert( XmlConstants.SchemaVersionLatest == XmlConstants.EdmVersionForV3, "Please add checking for the latest namespace"); AddError(ErrorCode.NoCodeGenNamespaceInStructuralAnnotation, EdmSchemaErrorSeverity.Error, lineNumber, linePosition, Strings.NoCodeGenNamespaceInStructuralAnnotation(XmlConstants.CodeGenerationSchemaNamespace)); return(true); } Debug.Assert( !Schema.IsParseableXmlNamespace(reader.NamespaceURI, false), "Structural annotation cannot use any edm reserved namespaces"); // using this subtree aproach because when I call // reader.ReadOuterXml() it positions me at the Node beyond // the end of the node I am starting on // which doesn't work with the parsing logic using (XmlReader subtree = reader.ReadSubtree()) { subtree.Read(); XElement element = XElement.Load(new StringReader(subtree.ReadOuterXml())); property = CreateMetadataPropertyFromOtherNamespaceXmlArtifact(element.Name.NamespaceName, element.Name.LocalName, element); } } else { if (reader.NamespaceURI == XmlNamespaceNamespace) { // we don't bring in namespace definitions return(true); } Debug.Assert(reader.NodeType == XmlNodeType.Attribute, "called an attribute function when not on an attribute"); property = CreateMetadataPropertyFromOtherNamespaceXmlArtifact(reader.NamespaceURI, reader.LocalName, reader.Value); } if (!OtherContent.Exists(mp => mp.Identity == property.Identity)) { OtherContent.Add(property); } else { AddError(ErrorCode.AlreadyDefined, EdmSchemaErrorSeverity.Error, lineNumber, linePosition, Strings.DuplicateAnnotation(property.Identity, this.FQName)); } return(false); }