public static void SetOrCreateXmlAttribute(XPathNavigator node, string localName, string namespaceURI, string value) { if (node.MoveToAttribute(localName, namespaceURI)) { node.SetValue(value); node.MoveToParent(); } else { node.CreateAttribute("", localName, namespaceURI, value); } }
private void createSubplatform(XPathNavigator navLocal, XmlDocument document, XPathNavigator navGlobal) { //itSubplatforms.Current.CreateAttribute(String.Empty, "name", String.Empty, cName + "Subplatform" + subplatNum++ + AME.Tools.ImportTool.Delimitter + "Subplatform"); String eventName = navLocal.SelectSingleNode("parent::node()").GetAttribute("name", navLocal.NamespaceURI); // Set up component values String cType = "Subplatform"; String cName; String cDescription = String.Empty; // Create links #region links // SubplatformKind String kind = (navLocal.SelectSingleNode("Kind") == null) ? String.Empty : navLocal.SelectSingleNode("Kind").Value; kind = kind.Trim(); if (navGlobal.SelectSingleNode(String.Format("/Scenario/Species[Name='{0}']", kind)) != null) { // Create component _ Want Kind in the component name. cName = navLocal.GetAttribute("name", navLocal.NamespaceURI) + AME.Tools.ImportTool.Delimitter + kind + "_" + cType; navLocal.MoveToAttribute("name", navLocal.NamespaceURI); navLocal.SetValue(cName); navLocal.MoveToParent(); createComponent(VSGConfiguration, document, cType, cName, cDescription); createLink(VSGConfiguration, document, cName, cName, kind, "SubplatformKind", String.Empty); } else { cName = navLocal.GetAttribute("name", navLocal.NamespaceURI); // Create component createComponent(VSGConfiguration, document, cType, cName, cDescription); } // Scenario Link createLink(VSGConfiguration, document, navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), eventName, cName, "Scenario", String.Empty); #endregion // Create parameters #region parameters if (navLocal.SelectSingleNode("Docked") != null) createParameter(VSGConfiguration, document, cName, "Component", "Subplatform.DockedCount", (navLocal.SelectSingleNode("Docked/Count") == null) ? String.Empty : navLocal.SelectSingleNode("Docked/Count").Value, String.Empty); #endregion // Armaments Int32 armamentNum = 0; XPathNodeIterator itArmaments = navLocal.Select("Armament"); while (itArmaments.MoveNext()) { itArmaments.Current.CreateAttribute(String.Empty, "name", String.Empty, cName + "Armament" + armamentNum++ + AME.Tools.ImportTool.Delimitter + "Armament"); createArmament(itArmaments.Current, document, navGlobal); } }
private static void ApplyReplace(XPathNavigator xpNav, XmlReplaceOptions opt, Regex rxFind) { string strData; if(opt.Data == XmlReplaceData.InnerText) strData = xpNav.Value; else if(opt.Data == XmlReplaceData.InnerXml) strData = xpNav.InnerXml; else if(opt.Data == XmlReplaceData.OuterXml) strData = xpNav.OuterXml; else return; if(strData == null) { Debug.Assert(false); strData = string.Empty; } string str = null; if(rxFind != null) str = rxFind.Replace(strData, opt.ReplaceText); else { if((opt.Flags & XmlReplaceFlags.CaseSensitive) != XmlReplaceFlags.None) str = strData.Replace(opt.FindText, opt.ReplaceText); else str = StrUtil.ReplaceCaseInsensitive(strData, opt.FindText, opt.ReplaceText); } if((str != null) && (str != strData)) { if(opt.Data == XmlReplaceData.InnerText) xpNav.SetValue(str); else if(opt.Data == XmlReplaceData.InnerXml) xpNav.InnerXml = str; else if(opt.Data == XmlReplaceData.OuterXml) xpNav.OuterXml = str; else { Debug.Assert(false); } } }
private static void Merge(XPathNavigator DstNavi, XmlDocument SrcDoc, string Parent) { var Current = NodePath(Parent, NodeView(DstNavi)); if (!string.IsNullOrWhiteSpace(Current)) { if (DstNavi.NodeType == XPathNodeType.Element) { var SrcElem = SrcDoc.SelectSingleNode(Current); if (SrcElem != null) { var Frozen = GetFrozenAttributes(Current, FrozenAttributes); if (DstNavi.MoveToFirstAttribute()) { do { var SrcElemAttr = SrcElem.Attributes[DstNavi.LocalName]; if (SrcElemAttr != null && CanProcess(DstNavi.LocalName, Frozen)) DstNavi.SetValue(SrcElemAttr.Value); } while (DstNavi.MoveToNextAttribute()); DstNavi.MoveToParent(); } } } else if (DstNavi.NodeType == XPathNodeType.Text) { var SrcElem = SrcDoc.SelectSingleNode(Current); if (SrcElem != null) DstNavi.SetValue(SrcElem.InnerText); } if (DstNavi.MoveToFirstChild()) { do { Merge(DstNavi, SrcDoc, Current); } while (DstNavi.MoveToNext()); DstNavi.MoveToParent(); } else if (DstNavi.NodeType == XPathNodeType.Element) { var SrcElem = SrcDoc.SelectSingleNode(Current); if (SrcElem != null && !string.IsNullOrWhiteSpace(SrcElem.InnerXml)) foreach (XmlNode Child in SrcElem.ChildNodes) DstNavi.AppendChild(Child.CloneNode(true).CreateNavigator()); } } }