internal StoreMemberProperty(EDMXFile parentFile, StoreEntityType storeEntityType, string name, int ordinal, XmlElement parentTypeElement) : base(parentFile) { _parentEntityType = storeEntityType; _parentEntityType.Removed += new EventHandler(ParentEntityType_Removed); _propertyElement = EDMXDocument.CreateElement("Property", NameSpaceURIssdl); if (ordinal > 0) { XmlNodeList propertyNodes = parentTypeElement.SelectNodes("ssdl:Property", NSM); if (propertyNodes.Count >= ordinal) { parentTypeElement.InsertAfter(_propertyElement, propertyNodes[ordinal - 1]); } else { parentTypeElement.AppendChild(_propertyElement); } } else { parentTypeElement.AppendChild(_propertyElement); } this.Name = name; }
internal ModelFunctionParameter(EDMXFile parentFile, ModelFunction storeFunction, string name, int ordinal, XmlElement parentTypeElement) : base(parentFile) { _parentFunction = storeFunction; _parameterElement = EDMXDocument.CreateElement("Parameter", NameSpaceURIcsdl); if (ordinal > 0) { XmlNodeList propertyNodes = parentTypeElement.SelectNodes("edm:Parameter", NSM); if (propertyNodes.Count >= ordinal) { parentTypeElement.InsertAfter(_parameterElement, propertyNodes[ordinal - 1]); } else { parentTypeElement.AppendChild(_parameterElement); } } else { parentTypeElement.AppendChild(_parameterElement); } this.Name = name; }
internal ModelMemberProperty(EDMXFile parentFile, ModelEntityType modelEntityType, string name, int ordinal, XmlElement entityTypeElement) : base(parentFile) { _modelEntityType = modelEntityType; _modelEntityType.Removed += new EventHandler(ModelEntityType_Removed); _propertyElement = EDMXDocument.CreateElement("Property", NameSpaceURIcsdl); if (ordinal > 0) { XmlNodeList propertyNodes = entityTypeElement.SelectNodes("edm:Property", NSM); if (propertyNodes.Count >= ordinal) { entityTypeElement.InsertAfter(_propertyElement, propertyNodes[ordinal - 1]); } else { entityTypeElement.AppendChild(_propertyElement); } } else { entityTypeElement.AppendChild(_propertyElement); } Name = name; }
/// <summary> /// Appends the specified action to the specified XML action model. The "group-hint" /// attribute of the action to be inserted is compared with the "group-hint" of the /// actions in the xml model and an appropriate place to insert the action is determined /// based on the MatchScore method of the <see cref="GroupHint"/>. /// </summary> /// <param name="xmlActionModel">the "action-model" node to insert an action into</param> /// <param name="action">the action to be inserted</param> /// <returns>a boolean indicating whether anything was added/removed/modified</returns> private static bool AppendActionToXmlModel(XmlDocument document, XmlElement xmlActionModel, IAction action) { if (null != FindXmlAction(xmlActionModel, action)) return false; XmlNode insertionPoint = null; bool insertBefore = false; int currentGroupScore = 0; foreach (XmlElement xmlAction in xmlActionModel.GetElementsByTagName("action")) { string hint = xmlAction.GetAttribute("group-hint"); var groupHint = new GroupHint(hint); int groupScore = action.GroupHint.MatchScore(groupHint); if (groupScore > 0 && groupScore >= Math.Abs(currentGroupScore)) { //"greater than" current score insertionPoint = xmlAction; currentGroupScore = groupScore; insertBefore = false; } else if (groupScore < 0 && Math.Abs(groupScore) > Math.Abs(currentGroupScore)) { //"less than" insertionPoint = xmlAction; currentGroupScore = groupScore; insertBefore = true; } } XmlElement newXmlAction = CreateXmlAction(document, action); if (insertionPoint != null) { if (insertBefore) xmlActionModel.InsertBefore(newXmlAction, insertionPoint); else xmlActionModel.InsertAfter(newXmlAction, insertionPoint); } else xmlActionModel.AppendChild(newXmlAction); return true; }
private void AppendCreditNode(XmlElement root, string defaultX, string defaultY, string fontSize, string justify, string valign, string content) { if (string.IsNullOrEmpty(content)) { // do not add empty blocks return; } var doc = root.OwnerDocument; var creditNode = doc.CreateElement("credit"); creditNode.AddAttribute("page", "1"); var creditWordsNode = doc.CreateElement("credit-words"); creditNode.AppendChild(creditWordsNode); creditWordsNode.AddAttribute("default-x", defaultX); creditWordsNode.AddAttribute("default-y", defaultY); creditWordsNode.AddAttribute("font-size", fontSize); creditWordsNode.AddAttribute("justify", justify); creditWordsNode.AddAttribute("valign", valign); creditWordsNode.InnerText = content; var defaultsNode = root.SelectSingleNode("defaults"); if (defaultsNode != null) { root.InsertAfter(creditNode, defaultsNode); } else { root.AppendChild(creditNode); } }
/// <summary> /// Inspects a Component element. /// </summary> /// <param name="element">The Component element to inspect.</param> private void InspectComponentElement(XmlElement element) { XmlAttribute driverAddRemovePrograms = element.GetAttributeNode("DriverAddRemovePrograms"); XmlAttribute driverDeleteFiles = element.GetAttributeNode("DriverDeleteFiles"); XmlAttribute driverForceInstall = element.GetAttributeNode("DriverForceInstall"); XmlAttribute driverLegacy = element.GetAttributeNode("DriverLegacy"); XmlAttribute driverPlugAndPlayPrompt = element.GetAttributeNode("DriverPlugAndPlayPrompt"); XmlAttribute driverSequence = element.GetAttributeNode("DriverSequence"); XmlAttribute guid = element.GetAttributeNode("Guid"); XmlAttribute diskId = element.GetAttributeNode("DiskId"); if (null != driverAddRemovePrograms || null != driverDeleteFiles || null != driverForceInstall || null != driverLegacy || null != driverPlugAndPlayPrompt || null != driverSequence) { XmlElement driver = element.OwnerDocument.CreateElement("difxapp", "Driver", "http://schemas.microsoft.com/wix/DifxAppExtension"); if (this.OnError(InspectorTestType.NamespaceChanged, element, String.Format(CultureInfo.CurrentCulture, "The Component/@Driver* attributes are now set via the Driver element which is part of the DifxApp extension. An xmlns:difxapp=\"http://schemas.microsoft.com/wix/DifxAppExtension\" attribute should be added to the Wix element and these attributes should be moved to a 'difxapp:Driver' element without the 'Driver' prefix."))) { element.InsertAfter(driver, element.FirstChild); } // make a best-effort at handling the whitespace, this isn't guaranteed to work, so wixcop may need to be run more than once if (XmlNodeType.Whitespace == driver.PreviousSibling.NodeType) { element.InsertAfter(driver.PreviousSibling.Clone(), driver); } if (null != driverAddRemovePrograms) { element.Attributes.Remove(driverAddRemovePrograms); XmlAttribute addRemovePrograms = element.OwnerDocument.CreateAttribute("AddRemovePrograms"); addRemovePrograms.Value = driverAddRemovePrograms.Value; driver.Attributes.Append(addRemovePrograms); } if (null != driverDeleteFiles) { element.Attributes.Remove(driverDeleteFiles); XmlAttribute deleteFiles = element.OwnerDocument.CreateAttribute("DeleteFiles"); deleteFiles.Value = driverDeleteFiles.Value; driver.Attributes.Append(deleteFiles); } if (null != driverForceInstall) { element.Attributes.Remove(driverForceInstall); XmlAttribute forceInstall = element.OwnerDocument.CreateAttribute("ForceInstall"); forceInstall.Value = driverForceInstall.Value; driver.Attributes.Append(forceInstall); } if (null != driverLegacy) { element.Attributes.Remove(driverLegacy); XmlAttribute legacy = element.OwnerDocument.CreateAttribute("Legacy"); legacy.Value = driverLegacy.Value; driver.Attributes.Append(legacy); } if (null != driverPlugAndPlayPrompt) { element.Attributes.Remove(driverPlugAndPlayPrompt); XmlAttribute plugAndPlayPrompt = element.OwnerDocument.CreateAttribute("PlugAndPlayPrompt"); plugAndPlayPrompt.Value = driverPlugAndPlayPrompt.Value; driver.Attributes.Append(plugAndPlayPrompt); } if (null != driverSequence) { element.Attributes.Remove(driverSequence); XmlAttribute sequence = element.OwnerDocument.CreateAttribute("Sequence"); sequence.Value = driverSequence.Value; driver.Attributes.Append(sequence); } // put the difxapp xmlns attribute on the root element if (null == element.OwnerDocument.DocumentElement.Attributes["xmlns:difxapp"]) { element.OwnerDocument.DocumentElement.SetAttribute("xmlns:difxapp", "http://schemas.microsoft.com/wix/DifxAppExtension"); } } if (null != diskId) { int numericDiskId; if (Int32.TryParse(diskId.Value, out numericDiskId) && 1 == numericDiskId) { if (this.OnError(InspectorTestType.DefaultOptionalAttribute, diskId, "The Component/@DiskId value is set to its default value of 1. Omit the DiskId attribute for simplified authoring.")) { element.Attributes.Remove(diskId); } } } }
/// <summary> Sets the value of a <code><property></code> child of the specified /// node. If a <code><property></code> element already exists, its value /// is updated; otherwise a new element is appended to the node. /// /// </summary> /// <param name="parentNode">The parent node of the property /// </param> /// <param name="property">The name of the property /// </param> /// <param name="value">The property value /// </param> public static void SetProperty( XmlElement parentNode, string property, string val ) { XmlElement propN = GetElementByAttribute ( parentNode, AdkXmlConstants.Property.ELEMENT, AdkXmlConstants.Property.NAME, property, false ); if ( propN == null ) { propN = parentNode.OwnerDocument.CreateElement( AdkXmlConstants.Property.ELEMENT ); // Search for another node in the config that matches the prefix of the current // property element and insert the node immediately after it, if found. // This helps to keep the property file in an easier to read format. int loc = property.Length - 1; XmlNode lastSibling = null; while ( lastSibling == null && (loc = property.LastIndexOf( '.', loc - 1 )) > -1 ) { string prefix = property.Substring( 0, loc + 1 ); lastSibling = FindLastPropertySibling( parentNode, prefix ); } if ( lastSibling == null ) { // Find the last property element lastSibling = FindLastPropertySibling( parentNode, null ); } if ( lastSibling != null ) { parentNode.InsertAfter( propN, lastSibling ); } else { parentNode.AppendChild( propN ); } } propN.SetAttribute( AdkXmlConstants.Property.NAME, property ); propN.SetAttribute( AdkXmlConstants.Property.VALUE, val ); }
private static void AddElements(XmlElement baseElement, XmlNodeList patchNodes, Position position) { if (position == Position.before) { foreach (XmlNode node in patchNodes) { XmlNode newEl = baseElement.OwnerDocument.ReadNode(new XmlNodeReader(node)); baseElement.ParentNode.InsertBefore(newEl, baseElement); } } else if (position == Position.after) { for (int i = 0; i < patchNodes.Count; i++) { XmlNode newEl = baseElement.OwnerDocument.ReadNode(new XmlNodeReader(patchNodes[patchNodes.Count - 1 - i])); baseElement.ParentNode.InsertAfter(newEl, baseElement); } } else if (position == Position.lastChild) { foreach (XmlNode node in patchNodes) { XmlNode newEl = baseElement.OwnerDocument.ReadNode(new XmlNodeReader(node)); baseElement.AppendChild(newEl); } } else if (position == Position.firstChild) { foreach (XmlNode node in patchNodes) { XmlNode newEl = baseElement.OwnerDocument.ReadNode(new XmlNodeReader(node)); baseElement.InsertAfter(newEl, null); } } }
/// <summary> /// Appends a schema node to a parameter supplied root element if it does not exist in <see cref="xDoc"/>. /// </summary> /// <param name="root">The document-level root element.</param> /// <param name="schemaName">The schema name to which the node is to refer.</param> /// <param name="previousElement">Use this as reference element to nsert the scheam ref element.</param> protected void AppendSchemaRef(XmlElement root, string schemaName, XmlElement previousElement) { // check to see if it already exists if ( this.xDoc.SelectSingleNode( string.Format( "//link:schemaRef[@xlink:href=\"{0}\"]", schemaName ), theManager ) == null ) { // add it XmlElement schemaRef = xDoc.CreateElement(DocumentBase.XBRL_LINKBASE_PREFIX, SCHEMA_REF, DocumentBase.XBRL_LINKBASE_URL); XmlAttribute typeAttr = xDoc.CreateAttribute( DocumentBase.XLINK_PREFIX, TYPE, DocumentBase.XLINK_URI ); typeAttr.Value = SIMPLE; schemaRef.SetAttributeNode( typeAttr ); XmlAttribute hrefAttr = xDoc.CreateAttribute(DocumentBase.XLINK_PREFIX, HREF, DocumentBase.XLINK_URI); hrefAttr.Value = schemaName; schemaRef.SetAttributeNode( hrefAttr ); previousElement.InsertAfter(schemaRef, null); // insert it first } }
static void SearchAndReplaceInParagraph(XmlElement paragraph, string search, string replace, bool matchCase) { XmlDocument xmlDoc = paragraph.OwnerDocument; string wordNamespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"; XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); nsmgr.AddNamespace("w", wordNamespace); XmlNodeList paragraphText = paragraph.SelectNodes("descendant::w:t", nsmgr); StringBuilder sb = new StringBuilder(); foreach (XmlNode text in paragraphText) sb.Append(((XmlElement)text).InnerText); if (sb.ToString().Contains(search) || (!matchCase && sb.ToString().ToUpper().Contains(search.ToUpper()))) { XmlNodeList runs = paragraph.SelectNodes("child::w:r", nsmgr); foreach (XmlElement run in runs) { XmlNodeList childElements = run.SelectNodes("child::*", nsmgr); if (childElements.Count > 0) { XmlElement last = (XmlElement)childElements[childElements.Count - 1]; for (int c = childElements.Count - 1; c >= 0; --c) { if (childElements[c].Name == "w:rPr") continue; if (childElements[c].Name == "w:t") { string textElementString = childElements[c].InnerText; for (int i = textElementString.Length - 1; i >= 0; --i) { XmlElement newRun = xmlDoc.CreateElement("w:r", wordNamespace); XmlElement runProps = (XmlElement)run.SelectSingleNode("child::w:rPr", nsmgr); if (runProps != null) { XmlElement newRunProps = (XmlElement)runProps.CloneNode(true); newRun.AppendChild(newRunProps); } XmlElement newTextElement = xmlDoc.CreateElement("w:t", wordNamespace); XmlText newText = xmlDoc.CreateTextNode(textElementString[i].ToString()); newTextElement.AppendChild(newText); if (textElementString[i] == ' ') { XmlAttribute xmlSpace = xmlDoc.CreateAttribute( "xml", "space", "http://www.w3.org/XML/1998/namespace"); xmlSpace.Value = "preserve"; newTextElement.Attributes.Append(xmlSpace); } newRun.AppendChild(newTextElement); paragraph.InsertAfter(newRun, run); } } else { XmlElement newRun = xmlDoc.CreateElement("w:r", wordNamespace); XmlElement runProps = (XmlElement)run.SelectSingleNode("child::w:rPr", nsmgr); if (runProps != null) { XmlElement newRunProps = (XmlElement)runProps.CloneNode(true); newRun.AppendChild(newRunProps); } XmlElement newChildElement = (XmlElement)childElements[c].CloneNode(true); newRun.AppendChild(newChildElement); paragraph.InsertAfter(newRun, run); } } paragraph.RemoveChild(run); } } while (true) { bool cont = false; runs = paragraph.SelectNodes("child::w:r", nsmgr); for (int i = 0; i <= runs.Count - search.Length; ++i) { bool match = true; for (int c = 0; c < search.Length; ++c) { XmlElement textElement = (XmlElement)runs[i + c].SelectSingleNode("child::w:t", nsmgr); if (textElement == null) { match = false; break; } if (textElement.InnerText == search[c].ToString()) continue; if (!matchCase && textElement.InnerText.ToUpper() == search[c].ToString().ToUpper()) continue; match = false; break; } if (match) { XmlElement runProps = (XmlElement)runs[i].SelectSingleNode("descendant::w:rPr", nsmgr); XmlElement newRun = xmlDoc.CreateElement("w:r", wordNamespace); if (runProps != null) { XmlElement newRunProps = (XmlElement)runProps.CloneNode(true); newRun.AppendChild(newRunProps); } XmlElement newTextElement = xmlDoc.CreateElement("w:t", wordNamespace); XmlText newText = xmlDoc.CreateTextNode(replace); newTextElement.AppendChild(newText); if (replace[0] == ' ' || replace[replace.Length - 1] == ' ') { XmlAttribute xmlSpace = xmlDoc.CreateAttribute("xml", "space", "http://www.w3.org/XML/1998/namespace"); xmlSpace.Value = "preserve"; newTextElement.Attributes.Append(xmlSpace); } newRun.AppendChild(newTextElement); paragraph.InsertAfter(newRun, (XmlNode)runs[i]); for (int c = 0; c < search.Length; ++c) paragraph.RemoveChild(runs[i + c]); cont = true; break; } } if (!cont) break; } // Consolidate adjacent runs that have only text elements, and have the // same run properties. This isn't necessary to create a valid document, // however, having the split runs is a bit messy. XmlNodeList children = paragraph.SelectNodes("child::*", nsmgr); List<int> matchId = new List<int>(); int id = 0; for (int c = 0; c < children.Count; ++c) { if (c == 0) { matchId.Add(id); continue; } if (children[c].Name == "w:r" && children[c - 1].Name == "w:r" && children[c].SelectSingleNode("w:t", nsmgr) != null && children[c - 1].SelectSingleNode("w:t", nsmgr) != null) { XmlElement runProps = (XmlElement)children[c].SelectSingleNode("w:rPr", nsmgr); XmlElement lastRunProps = (XmlElement)children[c - 1].SelectSingleNode("w:rPr", nsmgr); if ((runProps == null && lastRunProps != null) || (runProps != null && lastRunProps == null)) { matchId.Add(++id); continue; } if (runProps != null && runProps.InnerXml != lastRunProps.InnerXml) { matchId.Add(++id); continue; } matchId.Add(id); continue; } matchId.Add(++id); } for (int i = 0; i <= id; ++i) { var x1 = matchId.IndexOf(i); var x2 = matchId.LastIndexOf(i); if (x1 == x2) continue; StringBuilder sb2 = new StringBuilder(); for (int z = x1; z <= x2; ++z) sb2.Append(((XmlElement)children[z] .SelectSingleNode("w:t", nsmgr)).InnerText); XmlElement newRun = xmlDoc.CreateElement("w:r", wordNamespace); XmlElement runProps = (XmlElement)children[x1].SelectSingleNode("child::w:rPr", nsmgr); if (runProps != null) { XmlElement newRunProps = (XmlElement)runProps.CloneNode(true); newRun.AppendChild(newRunProps); } XmlElement newTextElement = xmlDoc.CreateElement("w:t", wordNamespace); XmlText newText = xmlDoc.CreateTextNode(sb2.ToString()); newTextElement.AppendChild(newText); if (sb2[0] == ' ' || sb2[sb2.Length - 1] == ' ') { XmlAttribute xmlSpace = xmlDoc.CreateAttribute( "xml", "space", "http://www.w3.org/XML/1998/namespace"); xmlSpace.Value = "preserve"; newTextElement.Attributes.Append(xmlSpace); } newRun.AppendChild(newTextElement); paragraph.InsertAfter(newRun, children[x2]); for (int z = x1; z <= x2; ++z) paragraph.RemoveChild(children[z]); } var txbxParagraphs = paragraph.SelectNodes("descendant::w:p", nsmgr); foreach (XmlElement p in txbxParagraphs) SearchAndReplaceInParagraph((XmlElement)p, search, replace, matchCase); } }
private XmlElement ChangePrefixes(XmlDocument doc, XmlElement element) { string newPrefix; if (this.namespaceToNewPrefixMapping.TryGetValue(element.NamespaceURI, out newPrefix)) { XmlElement newElement = doc.CreateElement(newPrefix, element.LocalName, element.NamespaceURI); List<XmlNode> children = new List<XmlNode>(element.ChildNodes.Cast<XmlNode>()); List<XmlAttribute> attributes = new List<XmlAttribute>(element.Attributes.Cast<XmlAttribute>()); foreach (XmlNode child in children) { newElement.AppendChild(child); } foreach (XmlAttribute attr in attributes) { newElement.Attributes.Append(attr); } element = newElement; } List<XmlAttribute> newAttributes = new List<XmlAttribute>(); bool modified = false; for (int i = 0; i < element.Attributes.Count; i++) { XmlAttribute attr = element.Attributes[i]; if (this.namespaceToNewPrefixMapping.TryGetValue(attr.NamespaceURI, out newPrefix)) { XmlAttribute newAttr = doc.CreateAttribute(newPrefix, attr.LocalName, attr.NamespaceURI); newAttr.Value = attr.Value; newAttributes.Add(newAttr); modified = true; } else if (attr.NamespaceURI == XmlnsNamespace && this.namespaceToNewPrefixMapping.TryGetValue(attr.Value, out newPrefix)) { XmlAttribute newAttr; if (newPrefix != "") { newAttr = doc.CreateAttribute("xmlns", newPrefix, XmlnsNamespace); } else { newAttr = doc.CreateAttribute("xmlns"); } newAttr.Value = attr.Value; newAttributes.Add(newAttr); modified = true; } else { newAttributes.Add(attr); } } if (modified) { element.Attributes.RemoveAll(); foreach (var attr in newAttributes) { element.Attributes.Append(attr); } } List<KeyValuePair<XmlNode, XmlNode>> toReplace = new List<KeyValuePair<XmlNode, XmlNode>>(); foreach (XmlNode child in element.ChildNodes) { XmlElement childElement = child as XmlElement; if (childElement != null) { XmlElement newChildElement = ChangePrefixes(doc, childElement); if (newChildElement != childElement) { toReplace.Add(new KeyValuePair<XmlNode, XmlNode>(childElement, newChildElement)); } } } if (toReplace.Count > 0) { for (int i = 0; i < toReplace.Count; i++) { element.InsertAfter(toReplace[i].Value, toReplace[i].Key); element.RemoveChild(toReplace[i].Key); } } return element; }
protected override void ExecuteCore(XmlElement element) { var child = CreateNode(element); if (!string.IsNullOrEmpty(After)) { try { if (After == "self") { element.ParentNode.InsertAfter(child, element); return; } var node = element.SelectSingleNode(After); if (node != null) { element.InsertAfter(child, node); return; } } catch (XPathException e) { var message = string.Format("'{0}' is not a valid XPath expression.", After); throw new TaskExecutionException(message, e); } catch (ArgumentException) { // The XPath expression is not valid IN THIS CONTEXT, e.g. an attribute was selected } } if (!string.IsNullOrEmpty(Before)) { try { if (Before == "self") { element.ParentNode.InsertBefore(child, element); return; } var node = element.SelectSingleNode(Before); if (node != null) { element.InsertBefore(child, node); return; } } catch (XPathException e) { var message = string.Format("'{0}' is not a valid XPath expression.", Before); throw new TaskExecutionException(message, e); } catch (ArgumentException) { // The XPath expression is not valid IN THIS CONTEXT, e.g. an attribute was selected } } element.AppendChild(child); }
private void CollectAntCodeCoverageForNode(string reportDirectory, string include, string exclude, XmlElement node, XmlDocument buildXml, XmlNode instrumentNode, string instrumentedClassesDirectory, string dataFile) { // add instrument node befor the test node. var parentNode = node.ParentNode; parentNode.InsertBefore(instrumentNode, node); node.SetAttribute("fork", "true"); _executionContext.Debug(StringUtil.Format(CodeCoverageConstants.SettingAttributeTemplate, "fork", "true", "test")); RemoveSysNodes(node); var coberturaCoverageElement = buildXml.CreateElement("sysproperty"); coberturaCoverageElement.SetAttribute("key", "net.sourceforge.cobertura.datafile"); coberturaCoverageElement.SetAttribute("file", dataFile); node.InsertBefore(coberturaCoverageElement, node.FirstChild); var instrumentElement = buildXml.CreateElement("classpath"); instrumentElement.SetAttribute("location", instrumentedClassesDirectory); node.InsertAfter(instrumentElement, node.FirstChild); var classPathElement = buildXml.CreateElement("classpath"); classPathElement.SetAttribute("refid", CodeCoverageConstants.CoberturaClassPathString); node.InsertAfter(classPathElement, node.LastChild); }
/// <summary> /// Appends unit nodes to a parameter supplied root element if they do not exist in <see cref="xDoc"/>. /// Sets the "unitRef" attribute to reflect the unit id /// of a parameter-supplied <see cref="UnitProperty"/>. /// </summary> /// <param name="root">The document-level root element to which elements will be appended.</param> /// <param name="elem">The element whose attributes are to be set.</param> /// <param name="errors">A collection of <see cref="String"/> objects to which method /// will append any errors.</param> /// <param name="presProp">A <see cref="Precision"/> from which precision attributes will be created.</param> /// <param name="unit">A <see cref="UnitProperty"/> from which unit elements will be created.</param> protected void AppendUnitInfo(XmlElement root, XmlElement elem, UnitProperty unit, Precision presProp, ArrayList errors) { elem.SetAttribute( UNIT_REF, unit.UnitID ); if ( presProp != null ) { elem.Attributes.Append( presProp.CreateAttribute( xDoc ) ); } string mergeKey = mergeDocs ? @"//link2:" : @"//"; if ( this.xDoc.SelectSingleNode( string.Format( mergeKey + "unit[@id=\"{0}\"]", unit.UnitID ), theManager ) == null ) { XmlElement unitNode = null; if ( mergeDocs ) { units.Add( unit ); if ( unit.CreateElementWithNamespaces( xDoc, root, errors, out unitNode, this.writeComments ) ) { root.InsertAfter( unitNode, unitComment ); } } else { if ( unit.CreateElement( xDoc, root, errors, out unitNode, this.writeComments ) ) { root.InsertAfter( unitNode, unitComment ); } } } }
//<wssc:DerivedKeyToken wsu:Id="SecurityToken-32d4ce5f-8619-4d7f-b0e2-f900b7aef082" wssc:Algorithm="http://schemas.xmlsoap.org/ws/2004/04/security/sc/dk/p_sha1" xmlns:wssc="http://schemas.xmlsoap.org/ws/2004/04/sc"> // <wsse:SecurityTokenReference> // <wsse:Reference URI="uuid:c04ae4a1-2e3e-4ab9-8066-7e4a8ab7699c" ValueType="http://schemas.xmlsoap.org/ws/2004/04/security/sc/sct" /> // </wsse:SecurityTokenReference> // <wssc:Generation>0</wssc:Generation> // <wssc:Length>16</wssc:Length> // <wssc:Label>WS-SecureConversation</wssc:Label> // <wsse:Nonce>7ReuLXwwNiLRNHc9PtkINw==</wsse:Nonce> //</wssc:DerivedKeyToken> public XmlElement WriteXml(XmlDocument plainDoc, XmlElement parent, XmlElement after) { XmlElement derKeyTokElem = plainDoc.CreateElement(Pre.wssc, Elem.DerivedKeyToken, Ns.wssc); XmlAttribute idAttrib = plainDoc.CreateAttribute(Pre.wsu, Attrib.Id, Ns.wsuLatest); idAttrib.Value = this.id; derKeyTokElem.Attributes.Append(idAttrib); XmlAttribute algAttrib = plainDoc.CreateAttribute(Pre.wssc, Attrib.Algorithm, Ns.wssc); algAttrib.Value = this.algorithm; derKeyTokElem.Attributes.Append(algAttrib); //parent.AppendChild(derKeyTokElem); parent.InsertAfter(derKeyTokElem, after); XmlElement securityTokenReferenceElem = plainDoc.CreateElement(Pre.wsse, Elem.SecurityTokenReference, Ns.wsseLatest); derKeyTokElem.AppendChild(securityTokenReferenceElem); XmlElement referenceElem = plainDoc.CreateElement(Pre.wsse, Elem.Reference, Ns.wsseLatest); securityTokenReferenceElem.AppendChild(referenceElem); XmlAttribute uriAttrib = plainDoc.CreateAttribute(Attrib.URI); uriAttrib.Value = secTokRef.Reference.URI; referenceElem.Attributes.Append(uriAttrib); XmlAttribute valueTypeAttrib = plainDoc.CreateAttribute(Attrib.ValueType); valueTypeAttrib.Value = secTokRef.Reference.ValueType; XmlElement genElem = plainDoc.CreateElement(Pre.wssc, Elem.Generation, Ns.wssc); genElem.InnerText = this.generation.ToString(); derKeyTokElem.AppendChild(genElem); XmlElement lenElem = plainDoc.CreateElement(Pre.wssc, Elem.Length, Ns.wssc); lenElem.InnerText = this.length.ToString(); derKeyTokElem.AppendChild(lenElem); XmlElement labElem = plainDoc.CreateElement(Pre.wssc, Elem.Label, Ns.wssc); labElem.InnerText = this.label; derKeyTokElem.AppendChild(labElem); XmlElement nonElem = plainDoc.CreateElement(Pre.wsse, Elem.Nonce, Ns.wsseLatest); nonElem.InnerText = this.nonce; derKeyTokElem.AppendChild(nonElem); referenceElem.Attributes.Append(valueTypeAttrib); return derKeyTokElem; }
private void AddDynamicChildElement(XmlElement parentElement, ModMenuItem element) { XmlNode copy = parentElement.OwnerDocument.ImportNode(element.MenuXml.GetXmlElement(), true); if (!String.IsNullOrEmpty(element.Parent)) { XmlNode parentNode = parentElement.OwnerDocument.SelectSingleNode("descendant::siteMapNode[@key='" + element.Parent + "']"); if (!String.IsNullOrEmpty(element.InsertAfter)) { XmlNode afterNode = parentElement.SelectSingleNode("descendant::siteMapNode[@key='" + element.InsertAfter + "']"); parentNode.InsertAfter(copy, afterNode); }else parentNode.AppendChild(copy); } else if (!String.IsNullOrEmpty(element.InsertAfter)) { XmlNode afterNode = parentElement.OwnerDocument.SelectSingleNode("descendant::siteMapNode[@key='" + element.InsertAfter + "']"); parentElement.InsertAfter(copy, afterNode); } else { parentElement.AppendChild(copy); } }
internal void InsertAfter(XmlElement parent, XmlElement child, XmlElement reference) { parent.InsertAfter(child, reference); }
private void AppendElement(XmlElement waypoint, string filename, string elementName) { var comment = SelectSingleElement(waypoint, elementName); if (comment == null) { comment = m_doc.CreateElement(elementName, m_doc.DocumentElement.NamespaceURI); waypoint.InsertAfter(comment, SelectSingleElement(waypoint, ("name"))); } if (string.IsNullOrEmpty(comment.InnerText)) comment.InnerText = string.Format("Source: {0}", filename); else comment.InnerText = string.Format("{0} (Source: {1})", comment.InnerText, filename); }
/// <summary> /// Appends a context node to a parameter supplied root element if it does not exist in <see cref="xDoc"/>. /// Sets the "contextRef" attribute to reflect the context id of a parameter-supplied <see cref="ContextProperty"/>. /// </summary> /// <param name="root">The document-level root element to which elements will be appended.</param> /// <param name="elem">The element whose "contextRef" attribute is to be set.</param> /// <param name="context">The context for which an element is to be added and for which the contexts collections is /// to be updated.</param> /// <param name="taxonomies">A collection of <see cref="Taxonomy"/> used in writing segment and scenario information.</param> protected void AppendContextInfo(XmlElement root, XmlElement elem, ContextProperty context, Taxonomy[] taxonomies) { // context first string mergeKey = mergeDocs ? @"//link2:" : @"//"; if ( this.xDoc.SelectSingleNode( string.Format( mergeKey + "context[@id=\"{0}\"]", context.ContextID ), theManager ) == null ) { this.contexts.Add( context ); XmlElement contextElem = mergeDocs ? context.AppendWithNamespaces(xDoc, root, taxonomies) : context.Append(xDoc, root, taxonomies); root.InsertAfter( contextElem, contextComment ); } elem.SetAttribute( CONTEXT_REF, context.ContextID ); }