private int GetIndex(XmlSchemaAnnotation annotations, string nodeName) { if (annotations == null) { throw new XmlSchemaException($"Schema node {nodeName} is missing required numeric Notes value.\nAll xml schema nodes must have Notes specified except root node. "); } foreach (XmlSchemaAppInfo annotation in annotations.Items) { XmlNode node = annotation.Markup[0]; //Is null if it does not exist //0-1 for multi cell span,***later XmlAttribute att = node.Attributes["notes"]; if (att != null) { if (att.Value.Length > 1) { return(int.Parse(att.Value.Substring(0, 2).TrimEnd())); } else { return(int.Parse(att.Value)); } } } return(-1); }
void Write5_XmlSchemaAnnotation(XmlSchemaAnnotation o) { if ((object)o == null) { return; } WriteStartElement("annotation"); WriteAttribute(@"id", @"", ((System.String)o.@Id)); WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o); System.Xml.Schema.XmlSchemaObjectCollection a = (System.Xml.Schema.XmlSchemaObjectCollection)o.@Items; if (a != null) { for (int ia = 0; ia < a.Count; ia++) { XmlSchemaObject ai = (XmlSchemaObject)a[ia]; if (ai is XmlSchemaAppInfo) { Write7_XmlSchemaAppInfo((XmlSchemaAppInfo)ai); } else if (ai is XmlSchemaDocumentation) { Write6_XmlSchemaDocumentation((XmlSchemaDocumentation)ai); } } } WriteEndElement(); }
///<summary> ///</summary> ///<param name="asbie"></param> ///<returns></returns> public static XmlSchemaAnnotation GetASCCAnnotiation(IAscc ascc) { // Contains all the documentation items such as DictionaryEntryName IList <XmlNode> documentation = new List <XmlNode>(); AddDocumentation(documentation, "UniqueID", ascc.UniqueIdentifier); AddDocumentation(documentation, "VersionID", ascc.VersionIdentifier); AddDocumentation(documentation, "Cardinality", ascc.LowerBound + ".." + ascc.UpperBound); AddDocumentation(documentation, "SequencingKey", ascc.SequencingKey); AddDocumentation(documentation, "DictionaryEntryName", ascc.DictionaryEntryName); AddDocumentation(documentation, "Definition", ascc.Definition); AddDocumentation(documentation, "BusinessTermName", ascc.BusinessTerms); AddDocumentation(documentation, "AssociationType", EaAggregationKind.Shared.ToString()); AddDocumentation(documentation, "PropertyTermName", ascc.Name); // PropertyQualifierName could be extracted from the PropertyTermName (e.g. "My" in // "My_Address") but is not implement at this point AddDocumentation(documentation, "PropertyQualifierName", ""); AddDocumentation(documentation, "AssociatedObjectClassTermName", ascc.AssociatedAcc.Name); // AssociatedObjectClassQualifierTermName could be extracted from the AssociatedObjectClassTermName // (e.g. "My" in "My_Address") but is not implement at this point AddDocumentation(documentation, "AcronymCode", "ASBIE"); XmlSchemaAnnotation annotation = new XmlSchemaAnnotation(); annotation.Items.Add(new XmlSchemaDocumentation { Language = "en", Markup = documentation.ToArray() }); return(annotation); }
/// <summary> /// Gets a value indicating whether the XML schema annotation contains an annotation describing this attribute as a string type /// </summary> /// <param name="annotation">The XML schema annotation to inspect</param> /// <returns></returns> private static bool HasStringAnnotation(XmlSchemaAnnotation annotation) { XmlSchemaObjectCollection items = annotation.Items; foreach (XmlSchemaAppInfo appInfo in items.OfType <XmlSchemaAppInfo>()) { foreach (XmlNode node in appInfo.Markup) { XmlElement element = node as XmlElement; if (element == null) { return(false); } if (string.IsNullOrWhiteSpace(element.LocalName)) { return(false); } if (element.LocalName == "DataType" && element.InnerText == "String") { return(true); } } } return(false); }
private static XmlSchemaAnnotation GetAttributeAnnotation(ICdtSup sup) { var xml = new XmlDocument(); // Deviation from rule [R 9C95]: Generating only a subset of the defined annotations and added some additional annotations. var annNodes = new List <XmlNode>(); AddAnnotation(xml, annNodes, "PropertyTermName", sup.Name); AddAnnotation(xml, annNodes, "RepresentationTermName", sup.BasicType.Name); AddAnnotation(xml, annNodes, "PrimitiveTypeName", sup.BasicType.Name); AddAnnotation(xml, annNodes, "DataTypeName", sup.Cdt.Name); AddAnnotation(xml, annNodes, "UniqueID", sup.UniqueIdentifier); AddAnnotation(xml, annNodes, "VersionID", sup.VersionIdentifier); AddAnnotation(xml, annNodes, "DictionaryEntryName", sup.DictionaryEntryName); AddAnnotation(xml, annNodes, "Definition", sup.Definition); AddAnnotations(xml, annNodes, "BusinessTermName", sup.BusinessTerms); AddAnnotation(xml, annNodes, "ModificationAllowedIndicator", sup.ModificationAllowedIndicator.ToString().ToLower()); AddAnnotation(xml, annNodes, "LanguageCode", sup.LanguageCode); AddAnnotation(xml, annNodes, "AcronymCode", "SUP"); var ann = new XmlSchemaAnnotation(); ann.Items.Add(new XmlSchemaDocumentation { Language = "en", Markup = annNodes.ToArray() }); return(ann); }
/// <summary> /// Gets the documentation from the annotation element. /// </summary> /// <remarks> /// All documentation elements are added. All text nodes inside /// the documentation element are added. /// </remarks> static string GetDocumentation(XmlSchemaAnnotation annotation) { if (annotation == null) { return(""); } var documentationBuilder = new StringBuilder(); foreach (XmlSchemaObject schemaObject in annotation.Items) { var schemaDocumentation = schemaObject as XmlSchemaDocumentation; if (schemaDocumentation != null && schemaDocumentation.Markup != null) { foreach (XmlNode node in schemaDocumentation.Markup) { var textNode = node as XmlText; if (textNode != null && !string.IsNullOrEmpty(textNode.Data)) { documentationBuilder.Append(textNode.Data); } } } } return(documentationBuilder.ToString()); }
public override XmlSchemaObject VisitASTType(ASTType astType) { var t = new XmlSchemaComplexType { Name = astType.Name }; var fields = astType.Fields.Select(Visit); var all = new XmlSchemaAll(); foreach (var field in fields) { all.Items.Add(field); } t.Particle = all; var description = string.Join(" ", astType.Annotations.Select(a => a.Value)); var schemaAnnotation = new XmlSchemaAnnotation(); var docs = new XmlSchemaDocumentation { Markup = TextToNodeArray(description) }; schemaAnnotation.Items.Add(docs); t.Annotation = schemaAnnotation; this.Schema.Items.Add(t); ExtractElement(astType); return(t); }
public void Pass_XmlSchemaAnnotation_XmlSchemaGroup_XmlSchemaAny_Invalid(String TypeToPass) { XmlSchemaValidator val = CreateValidator(new XmlSchemaSet()); XmlSchemaObject obj = new XmlSchemaAnnotation(); switch (TypeToPass) { case "annotation": obj = new XmlSchemaAnnotation(); break; case "group": obj = new XmlSchemaGroup(); break; case "any": obj = new XmlSchemaAny(); break; default: Assert.True(false); break; } try { val.Initialize(obj); } catch (ArgumentException) { return; } Assert.True(false); }
private List <XmlNode> GetAnnotation(XmlSchemaAnnotated annotated) { List <XmlNode> nodes = new List <XmlNode>(); XmlSchemaAnnotation annotation = annotated.Annotation; if (annotation != null) { // find the first <xs:appinfo> element foreach (XmlSchemaObject schemaObj in annotation.Items) { XmlSchemaAppInfo appInfo = schemaObj as XmlSchemaAppInfo; if (appInfo != null) { // copy annotation, removing comments foreach (XmlNode node in appInfo.Markup) { if (node.NodeType != XmlNodeType.Comment) { nodes.Add(node); } } } } } return(nodes); }
private static XmlSchemaAnnotation?GetSchemaAnnotation(params XmlNode?[]?nodes) { if (nodes == null || nodes.Length == 0) { return(null); } bool hasAnnotation = false; for (int i = 0; i < nodes.Length; i++) { if (nodes[i] != null) { hasAnnotation = true; break; } } if (!hasAnnotation) { return(null); } XmlSchemaAnnotation annotation = new XmlSchemaAnnotation(); XmlSchemaAppInfo appInfo = new XmlSchemaAppInfo(); annotation.Items.Add(appInfo); appInfo.Markup = nodes; return(annotation); }
private static void PopulateEnumerationValues(X12_IdDataType idType, XmlSchemaElement element) { if (idType == null || idType.AllowedValues == null || idType.AllowedValues.Count == 0) { return; } XmlSchemaSimpleType simpleType = element.SchemaType as XmlSchemaSimpleType; XmlSchemaSimpleTypeRestriction restriction = simpleType.Content as XmlSchemaSimpleTypeRestriction; foreach (KeyValuePair <string, string> kvp in idType.AllowedValues) { XmlSchemaEnumerationFacet facet = new XmlSchemaEnumerationFacet(); facet.Value = kvp.Key; if (!string.IsNullOrEmpty(kvp.Value)) { XmlSchemaAnnotation annotation = new XmlSchemaAnnotation(); XmlSchemaDocumentation doc = new XmlSchemaDocumentation(); doc.Markup = TextToNodeArray(kvp.Value); annotation.Items.Add(doc); facet.Annotation = annotation; } restriction.Facets.Add(facet); } }
public static string ReadDocumentationFromEnumeration(XmlSchemaEnumerationFacet enumeration) { string documentation = string.Empty; XmlSchemaAnnotation annotation = enumeration.Annotation; if (annotation != null && annotation.Items != null) { XmlSchemaObjectCollection coll = annotation.Items; foreach (XmlSchemaObject obj in coll) { if (obj is XmlSchemaDocumentation) { XmlSchemaDocumentation doc = (XmlSchemaDocumentation)obj; XmlNode[] node = doc.Markup; if (node != null) { for (int i = 0; i < node.Length; i++) { if (node[i] is XmlText) { documentation = (node[i] as XmlText).InnerText; } } } } } } return(documentation); }
/// <summary> /// Gets the first sentence of a documentation element and returns it as a string. /// </summary> /// <param name="annotation">The annotation in which to look for a documentation element.</param> /// <returns>The string representing the first sentence, or null if none found.</returns> private static string GetDocumentation(XmlSchemaAnnotation annotation) { string documentation = null; if (annotation != null && annotation.Items != null) { foreach (XmlSchemaObject obj in annotation.Items) { XmlSchemaDocumentation schemaDocumentation = obj as XmlSchemaDocumentation; if (schemaDocumentation != null) { if (schemaDocumentation.Markup.Length > 0) { XmlText text = schemaDocumentation.Markup[0] as XmlText; if (text != null) { documentation = text.Value; } } break; } } } if (documentation != null) { documentation = documentation.Trim(); } return(documentation); }
private void AddInfo(XmlSchema xSchema, JsonSchema jSchema) { InfoKeyword info = jSchema.Get <InfoKeyword>(); if (info != null) { XmlSchemaAnnotation annotation = new XmlSchemaAnnotation(); XmlSchemaDocumentation documentation = new XmlSchemaDocumentation(); annotation.Items.Add(documentation); List <XmlElement> elements = new List <XmlElement>(); JsonObject infoObject = info.ToJson(new JsonSerializer()).Object; foreach (string attributeName in infoObject.Keys) { XmlElement attrElement = xmlDocument.CreateElement("xs", "attribute", XML_SCHEMA_NS); attrElement.SetAttribute("name", attributeName); attrElement.SetAttribute("fixed", infoObject.TryGetString(attributeName)); elements.Add(attrElement); } documentation.Markup = elements.ToArray(); xSchema.Items.Add(annotation); } }
public SchemaDocumentation(XmlSchemaAnnotation annotation) { _annotation = annotation; if (annotation != null) { ReadDocumentationFromAnnotation(annotation.Items); } }
/// <summary> /// Creates a XmlSchema object from a JSON Schema object /// </summary> /// <param name="jSchema">The Json Schema to convert</param> /// <returns>The converted XmlSchema object</returns> public XmlSchema CreateXsd(JsonSchema jSchema) { if (jSchema == null) { throw new Exception("Cannot create XSD from empty (null) JsonSchema"); } XmlSchema xsdSchema = new XmlSchema { ElementFormDefault = XmlSchemaForm.Qualified, AttributeFormDefault = XmlSchemaForm.Unqualified, }; xsdSchema.Namespaces.Add("brreg", BRREG_NS); AddInfo(xsdSchema, jSchema); string title = GetterExtensions.Title(jSchema); string description = GetterExtensions.Description(jSchema); if (!string.IsNullOrEmpty(title) || !string.IsNullOrEmpty(description)) { XmlSchemaAnnotation annotation = new XmlSchemaAnnotation(); AddTitleAndDescriptionAnnotations(jSchema, annotation); xsdSchema.Items.Add(annotation); } // Handle global element declarations Dictionary <string, JsonSchema> globalProperties = jSchema.Properties(); if (globalProperties != null) { foreach (KeyValuePair <string, JsonSchema> property in globalProperties) { XmlSchemaElement rootElement = new XmlSchemaElement { Name = property.Key, SchemaTypeName = GetTypeName(property.Value), }; AddAnnotations(rootElement, property.Value); xsdSchema.Items.Add(rootElement); } } // Handle all definitions Dictionary <string, JsonSchema> definitions = GetterExtensions.Definitions(jSchema); if (definitions != null) { foreach (KeyValuePair <string, JsonSchema> def in definitions) { ExtractProperties(xsdSchema, def.Key, def.Value); } } return(xsdSchema); }
/// <summary> /// Запись Annotation в новый файл XSD /// </summary> /// <param name="newschemaItem">Текущий экземпляр класса SeSchemaItem(список List(SeSchemaItem) класса SeSchema</param> /// <param name="discriptionAnn">Новый элемент XmlSchemaAnnotation</param> /// <returns>Измененный элемент XmlSchemaAnnotation</returns> public XmlSchemaAnnotation SetAnnotation(SeSchemaItem newschemaItem) { XmlSchemaAnnotation discriptionAnn = new XmlSchemaAnnotation(); XmlSchemaDocumentation discriptionDoc = new XmlSchemaDocumentation(); discriptionAnn.Items.Add(discriptionDoc); discriptionDoc.Markup = TextToNodeArray(newschemaItem.Description); return(discriptionAnn); }
private static string GetDocumentation(XmlSchemaAnnotation annotation) { if (annotation == null) { return(null); } var xDoc = annotation.Items.OfType <XmlSchemaDocumentation>().FirstOrDefault(); return(GetDocumentation(xDoc)); }
private XSAnnotation() { InternalObject = new XmlSchemaAnnotation(); Content = new XSComponentList(); Content.Cleared += Content_Cleared; Content.Inserted += Content_Inserted; Components = new XSComponentFixedList(); }
void AddAnnotation(XmlSchemaAnnotated element, string value) { var annotation = new XmlSchemaAnnotation(); var documentation = new XmlSchemaDocumentation(); var document = new XmlDocument(); documentation.Markup = new[] { document.CreateTextNode(value) }; annotation.Items.Add(documentation); element.Annotation = annotation; }
private static void ProcessPropertySchemas(XmlSchema schema, SchemaMetaData schemaMetaData) { XmlSchemaAnnotation annotation = null; if (schema != null && schemaMetaData != null) { if (schema.Items[0] is XmlSchemaAnnotation) { annotation = (XmlSchemaAnnotation)schema.Items[0]; } IEnumerator enumerator = (IEnumerator)annotation.Items.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current is XmlSchemaAppInfo) { XmlNode[] markup = ((XmlSchemaAppInfo)enumerator.Current).Markup; for (int index = 0; index < markup.Length; ++index) { if (markup[index].NamespaceURI == "http://schemas.microsoft.com/BizTalk/2003" && string.Compare(markup[index].LocalName, "imports", StringComparison.Ordinal) == 0) { XmlNode imports = markup[index]; foreach (XmlNode import in imports.ChildNodes) { XmlNode uri = import.Attributes.GetNamedItem("uri"); XmlNode location = import.Attributes.GetNamedItem("location"); Schema propSchema = GetPropertySchema(location.InnerText, uri.InnerText); foreach (DictionaryEntry item in propSchema.Properties) { foreach (var prop in schemaMetaData.Properties) { if (prop.Value.Namespace == propSchema.TargetNameSpace) { if (item.Key.ToString().EndsWith("." + prop.Value.Name)) { prop.Value.TypeCode = TypeFromXmlSchemaType(item.Value.ToString()); } } if (schemaMetaData.IsComplete) { break; } } } } } } break; } } } }
private static void SetDocumentation(IPluglet pluglet, XmlSchemaElement element) { if (!string.IsNullOrEmpty(pluglet.Definition)) { XmlSchemaAnnotation annotation = new XmlSchemaAnnotation(); XmlSchemaDocumentation doc = new XmlSchemaDocumentation(); doc.Markup = TextToNodeArray(pluglet.Definition); annotation.Items.Add(doc); element.Annotation = annotation; } }
public bool AddMaxDistanceConstraint(string Km, string Latitude, string Longitude) { double km, lat, lon; if (!double.TryParse(Km, out km) || km < 0) { return(false); } if (!double.TryParse(Latitude, out lat)) { return(false); } if (!double.TryParse(Longitude, out lon)) { return(false); } if (lat < -90 || lat > 90) { return(false); } if (lon < -180 || lon > 180) { return(false); } // custom constraint (close your eyes =) XmlSchemaComplexContentExtension cce = (XmlSchemaComplexContentExtension)((XmlSchemaComplexContent)(((XmlSchemaComplexType)baseSchema.Items[0])).ContentModel).Content; XmlSchemaAnnotation sa = (cce.Annotation == null) ? new XmlSchemaAnnotation() : cce.Annotation; cce.Annotation = sa; XmlSchemaDocumentation sd = new XmlSchemaDocumentation(); sa.Items.Add(sd); XmlDocument doc = new XmlDocument(); XmlNode node = doc.CreateElement("maxDistanceFrom"); sd.Markup = new XmlNode[1] { node }; node.AppendChild(doc.CreateElement("Distance")); node.AppendChild(doc.CreateElement("Latitude")); node.AppendChild(doc.CreateElement("Longitude")); node.ChildNodes[0].InnerText = km.ToString(); node.ChildNodes[1].InnerText = lat.ToString(); node.ChildNodes[2].InnerText = lon.ToString(); return(true); }
private XmlSchemaAnnotation GetSchemaAnnotation(XmlQualifiedName annotationQualifiedName, string innerText, XmlSchema schema) { XmlSchemaAnnotation annotation = new XmlSchemaAnnotation(); XmlSchemaAppInfo appInfo = new XmlSchemaAppInfo(); XmlElement annotationElement = GetAnnotationMarkup(annotationQualifiedName, innerText, schema); appInfo.Markup = new XmlNode[1] { annotationElement }; annotation.Items.Add(appInfo); return(annotation); }
public static void AddAppinfo(this XmlSchemaElement element, XmlSchemaAppInfo ai) { var annotation = element.Annotation; if (annotation == null) { annotation = new XmlSchemaAnnotation(); element.Annotation = annotation; } annotation.Items.Insert(0, ai); }
public void IterateThrough(XmlSchemaAnnotation obj) { if (_functionalVisitor.StartProcessing(obj)) { var en = obj.Items.GetEnumerator(); while (en.MoveNext()) { en.Current.Accept(this); } } _functionalVisitor.EndProcessing(obj); }
internal static XmlQualifiedName ImportActualType(XmlSchemaAnnotation annotation, XmlQualifiedName defaultTypeName, XmlQualifiedName typeName) { XmlElement element = ImportAnnotation(annotation, ActualTypeAnnotationName); if (element == null) { return(defaultTypeName); } string name = element.Attributes.GetNamedItem("Name").Value; return(new XmlQualifiedName(name, element.Attributes.GetNamedItem("Namespace").Value)); }
/// <summary> /// Extracts annotation section from passes XmlSchema object /// </summary> /// <param name="annotatedElement">Annotation element of XSD schema with documentation and appinfo tags</param> /// <returns>Extracted Documentation and AppInfo</returns> public static Dictionary <string, string> GetDocumentationForElement(XmlSchemaAnnotated annotatedElement) { Dictionary <string, string> annotationElements = new Dictionary <string, string>(); StringBuilder documatationHolder = new StringBuilder(); StringBuilder appInfoHolder = new StringBuilder(); XmlSchemaAnnotation annotation = annotatedElement.Annotation; // Look inside the Annotation element if (annotation != null) { XmlSchemaObjectCollection annotationItems = annotation.Items; if (annotationItems.Count > 0) { // Cannot use for..each for (int elementCount = 0; elementCount < annotationItems.Count; elementCount++) { XmlSchemaDocumentation xsdDocumentation = annotationItems[elementCount] as XmlSchemaDocumentation; if (xsdDocumentation != null) { XmlNode[] documentationMarkups = xsdDocumentation.Markup; if (documentationMarkups.Length > 0) { documatationHolder.Append(documentationMarkups[0].InnerText); documatationHolder.Append(" "); } } XmlSchemaAppInfo xsdAppInfo = annotationItems[elementCount] as XmlSchemaAppInfo; if (xsdAppInfo != null) { XmlNode[] appInfoMarkups = xsdAppInfo.Markup; if (appInfoMarkups.Length > 0) { appInfoHolder.Append(appInfoMarkups[0].InnerText); appInfoHolder.Append(" "); } } } if (documatationHolder.Length > 0) { annotationElements.Add("DOC", documatationHolder.ToString()); } if (appInfoHolder.Length > 0) { annotationElements.Add("APPINFO", appInfoHolder.ToString()); } } } return(annotationElements); }
/// <summary> /// Constructs a schema from the contents of an XML specification. /// </summary> /// <param name="fileContents">The contents of a file that specifies the schema in XML.</param> public AnnotationSchema(DataModelSchema dataModelSchema, XmlSchemaAnnotation xmlSchemaAnnotation) : base(dataModelSchema, xmlSchemaAnnotation) { this.itemList = new List <Object>(); foreach (XmlSchemaObject xmlSchemaObject in xmlSchemaAnnotation.Items) { if (xmlSchemaObject is XmlSchemaAppInfo) { this.itemList.Add(new AppInfoSchema(dataModelSchema, xmlSchemaObject as XmlSchemaAppInfo)); } } }
private void AddTitleAndDescriptionAnnotations(JsonSchema jSchema, XmlSchemaAnnotation annotation) { string description = GetterExtensions.Description(jSchema); if (description != null) { annotation.Items.Add(CreateSimpleDocumentation("description", description)); } string title = GetterExtensions.Title(jSchema); if (title != null) { annotation.Items.Add(CreateSimpleDocumentation("title", title)); } }
internal virtual void AddAnnotation(XmlSchemaAnnotation annotation) {}
internal override void AddAnnotation(XmlSchemaAnnotation annotation) { items.Add(annotation); }
} //WriteXmlSchemaElement() //XmlSchemaAnnotation public static void WriteXmlSchemaAnnotation(XmlSchemaAnnotation annotation, XmlTextWriter myXmlTextWriter) { // Not a complete implementation myXmlTextWriter.WriteStartElement("annotation", XmlSchema.Namespace); foreach (object o in annotation.Items) { if (o is XmlSchemaDocumentation) { myXmlTextWriter.WriteStartElement("documentation", XmlSchema.Namespace); XmlSchemaDocumentation xmlsd = (XmlSchemaDocumentation)o; foreach (XmlNode n in xmlsd.Markup) { myXmlTextWriter.WriteStartElement("documentation values", XmlSchema.Namespace); myXmlTextWriter.WriteString(n.Value); myXmlTextWriter.WriteEndElement(); } //foreach myXmlTextWriter.WriteEndElement(); } //if else { if (o is XmlSchemaAppInfo) { XmlSchemaAppInfo xsai = (XmlSchemaAppInfo)o; foreach (XmlNode n in xsai.Markup) { myXmlTextWriter.WriteStartElement("appinfo values", XmlSchema.Namespace); myXmlTextWriter.WriteString(n.Value); myXmlTextWriter.WriteEndElement(); } //foreach } //if } //else } //foreach myXmlTextWriter.WriteEndElement(); } //WriteXmlSchemaAnnotation()