/// <summary> /// write attributes to xtw (except blacklisted) /// </summary> /// <param name="attributes"> </param> /// <param name="xtw"> </param> /// <param name="blackLists"> </param> public static void WriteCustomAttributes(ICollection <IList <ExtensionAttribute> > attributes, XMLStreamWriter xtw, IDictionary <string, string> namespaceMap, params IList <ExtensionAttribute>[] blackLists) { foreach (IList <ExtensionAttribute> attributeList in attributes) { if (attributeList != null && attributeList.Count > 0) { foreach (ExtensionAttribute attribute in attributeList) { if (!IsBlacklisted(attribute, blackLists)) { if (attribute.NamespacePrefix == null) { if (attribute.Namespace == null) { xtw.WriteAttribute(attribute.Name, attribute.Value); } else { xtw.WriteAttribute(attribute.Namespace, attribute.Name, attribute.Value); } } else { if (!namespaceMap.ContainsKey(attribute.Name)) { namespaceMap[attribute.Name] = attribute.Namespace; xtw.WriteNamespace(attribute.NamespacePrefix, attribute.Namespace); } xtw.WriteAttribute(attribute.NamespacePrefix, attribute.Namespace, attribute.Name, attribute.Value); } } } } } }
public static void WriteRootElement(BpmnModel model, XMLStreamWriter xtw, string encoding) { xtw.WriteStartDocument(encoding, "1.0"); // start definitions root element xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_DEFINITIONS, BpmnXMLConstants.BPMN2_NAMESPACE); xtw.DefaultNamespace = BpmnXMLConstants.BPMN2_NAMESPACE; xtw.WriteDefaultNamespace(BpmnXMLConstants.BPMN2_NAMESPACE); xtw.WriteNamespace(BpmnXMLConstants.XSI_PREFIX, BpmnXMLConstants.XSI_NAMESPACE); xtw.WriteNamespace(BpmnXMLConstants.XSD_PREFIX, BpmnXMLConstants.SCHEMA_NAMESPACE); xtw.WriteNamespace(BpmnXMLConstants.ACTIVITI_EXTENSIONS_PREFIX, BpmnXMLConstants.ACTIVITI_EXTENSIONS_NAMESPACE); xtw.WriteNamespace(BpmnXMLConstants.BPMNDI_PREFIX, BpmnXMLConstants.BPMNDI_NAMESPACE); xtw.WriteNamespace(BpmnXMLConstants.OMGDC_PREFIX, BpmnXMLConstants.OMGDC_NAMESPACE); xtw.WriteNamespace(BpmnXMLConstants.OMGDI_PREFIX, BpmnXMLConstants.OMGDI_NAMESPACE); foreach (string prefix in model.Namespaces.Keys) { if (!defaultNamespaces.Contains(prefix) && !string.IsNullOrWhiteSpace(prefix)) { xtw.WriteNamespace(prefix, model.Namespaces[prefix]); } } xtw.WriteAttribute(BpmnXMLConstants.TYPE_LANGUAGE_ATTRIBUTE, BpmnXMLConstants.SCHEMA_NAMESPACE); xtw.WriteAttribute(BpmnXMLConstants.EXPRESSION_LANGUAGE_ATTRIBUTE, BpmnXMLConstants.XPATH_NAMESPACE); if (!string.IsNullOrWhiteSpace(model.TargetNamespace)) { xtw.WriteAttribute(BpmnXMLConstants.TARGET_NAMESPACE_ATTRIBUTE, model.TargetNamespace); } else { xtw.WriteAttribute(BpmnXMLConstants.TARGET_NAMESPACE_ATTRIBUTE, BpmnXMLConstants.PROCESS_NAMESPACE); } //BpmnXMLUtil.WriteCustomAttributes(model.DefinitionsAttributes.Values, xtw, model.Namespaces, defaultAttributes); }
protected internal static void WriteExtensionElement(ExtensionElement extensionElement, IDictionary <string, string> namespaceMap, XMLStreamWriter xtw) { if (!string.IsNullOrWhiteSpace(extensionElement.Name)) { IDictionary <string, string> localNamespaceMap = new Dictionary <string, string>(); if (!string.IsNullOrWhiteSpace(extensionElement.Namespace)) { if (!string.IsNullOrWhiteSpace(extensionElement.NamespacePrefix)) { xtw.WriteStartElement(extensionElement.NamespacePrefix, extensionElement.Name, extensionElement.Namespace); if (!namespaceMap.ContainsKey(extensionElement.NamespacePrefix) || !namespaceMap[extensionElement.NamespacePrefix].Equals(extensionElement.Namespace)) { xtw.WriteNamespace(extensionElement.NamespacePrefix, extensionElement.Namespace); namespaceMap[extensionElement.NamespacePrefix] = extensionElement.Namespace; localNamespaceMap[extensionElement.NamespacePrefix] = extensionElement.Namespace; } } else { xtw.WriteStartElement(extensionElement.Namespace, extensionElement.Name); } } else { xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, extensionElement.Name, BpmnXMLConstants.BPMN2_NAMESPACE); } foreach (IList <ExtensionAttribute> attributes in extensionElement.Attributes.Values) { foreach (ExtensionAttribute attribute in attributes) { if (!string.IsNullOrWhiteSpace(attribute.Name) && attribute.Value != null) { if (!string.IsNullOrWhiteSpace(attribute.Namespace)) { if (!string.IsNullOrWhiteSpace(attribute.NamespacePrefix)) { if (!namespaceMap.ContainsKey(attribute.NamespacePrefix) || !namespaceMap[attribute.NamespacePrefix].Equals(attribute.Namespace)) { xtw.WriteNamespace(attribute.NamespacePrefix, attribute.Namespace); namespaceMap[attribute.NamespacePrefix] = attribute.Namespace; } xtw.WriteAttribute(attribute.NamespacePrefix, attribute.Namespace, attribute.Name, attribute.Value); } else { xtw.WriteAttribute(attribute.Namespace, attribute.Name, attribute.Value); } } else { xtw.WriteAttribute(attribute.Name, attribute.Value); } } } } if (extensionElement.ElementText != null) { xtw.WriteCData(extensionElement.ElementText); } else { foreach (IList <ExtensionElement> childElements in extensionElement.ChildElements.Values) { foreach (ExtensionElement childElement in childElements) { WriteExtensionElement(childElement, namespaceMap, xtw); } } } foreach (string prefix in localNamespaceMap.Keys) { namespaceMap.Remove(prefix); } xtw.WriteEndElement(); } }