public static void PerformQTConfigPatches(string devenvroot, string agentExecutable, string subpath, IDictionary<Assembly, KeyValuePair<bool, bool?>> actions) { var agentConfigFile = Path.Combine(devenvroot, agentExecutable + ".config"); string ns = "urn:schemas-microsoft-com:asm.v1"; var x = new XmlDocument(); x.Load(agentConfigFile); var nsm = new XmlNamespaceManager(x.NameTable); var prf = nsm.LookupPrefix(ns); if (string.IsNullOrEmpty(prf)) nsm.AddNamespace(prf = "asm1", ns); bool changed = false; foreach (var pair in actions) { var asm = pair.Key; var cleanup = pair.Value.Key; var newstate = pair.Value.Value; var filepath = Path.Combine(subpath, Path.GetFileName(asm.Location)); if (cleanup) changed |= junkRemover(x, asm.GetName(), ns, prf, nsm); if (newstate == true) changed |= exactWriter(x, filepath, asm.GetName(), ns, prf, nsm); else if (newstate == false) changed |= exactRemover(x, filepath, asm.GetName(), ns, prf, nsm); } if (changed) x.Save(agentConfigFile); }
public XmlValidationRuleset(IXmlDocumentProvider docProvider, XmlNode node, XmlNamespaceManager nsmgr) { if (node.Attributes["name"] != null) this.Name = node.Attributes["name"].Value; if (node.Attributes["nameString"] != null) this.NameString = node.Attributes["nameString"].Value; if (node.Attributes["descriptionString"] != null) this.DescriptionString = node.Attributes["descriptionString"].Value; List<IValidationRule> rules = new List<IValidationRule>(); string prefix = nsmgr.LookupPrefix("http://icalvalid.wikidot.com/validation"); if (node.Attributes["basedOn"] != null) { // Inherit rules from the ruleset this one is based on. string name = node.Attributes["basedOn"].Value; foreach (XmlNode rule in node.SelectNodes("parent::" + prefix + ":rulesets/" + prefix + ":ruleset[@name='" + name + "']/" + prefix + ":rule", nsmgr)) rules.Add(new XmlValidationRule(docProvider, rule, nsmgr)); } foreach (XmlNode rule in node.SelectNodes(prefix + ":rule", nsmgr)) rules.Add(new XmlValidationRule(docProvider, rule, nsmgr)); Rules = rules.ToArray(); }
public XmlValidationRule(IXmlDocumentProvider docProvider, XmlNode node, XmlNamespaceManager nsmgr) { if (node.Attributes["name"] != null) Name = node.Attributes["name"].Value; if (node.Attributes["file"] != null) File = node.Attributes["file"].Value; if (!string.IsNullOrEmpty(File)) { try { XmlDocument doc = docProvider.Load(File); if (doc != null) { List<ITest> tests = new List<ITest>(); string prefix = nsmgr.LookupPrefix("http://icalvalid.wikidot.com/validation"); foreach (XmlNode passNode in doc.SelectNodes("/" + prefix + ":rule/" + prefix + ":pass", nsmgr)) tests.Add(new XmlCalendarTest(passNode, nsmgr)); foreach (XmlNode failNode in doc.SelectNodes("/" + prefix + ":rule/" + prefix + ":fail", nsmgr)) tests.Add(new XmlCalendarTest(failNode, nsmgr)); Tests = tests.ToArray(); } else throw new ValidationRuleLoadException("The file could not be found at the following path: '" + File + "'.", this); } catch (ValidationRuleLoadException) { throw; } catch { throw new ValidationRuleLoadException(this); } } }
public override void LoadFromXml(XmlElement el, XmlNamespaceManager nsmgr) { base.LoadFromXml(el, nsmgr); string pr = nsmgr.LookupPrefix(ProcessDefinition.WORKFLOW_NAMESPACE); if (pr != null && pr.Length > 0) pr += ":"; VariableDir = (VariableDef.Dir)Enum.Parse(typeof(VariableDef.Dir), el.GetAttribute("dir")); DefaultValueExpr = SchemaUtil.GetXmlElementText(el, pr + "defaultValue", nsmgr); }
private string ResolveFullName(IXmlNode node, XmlNamespaceManager manager) { string str = node.NamespaceUri == null || node.LocalName == "xmlns" && node.NamespaceUri == "http://www.w3.org/2000/xmlns/" ? (string) null : manager.LookupPrefix(node.NamespaceUri); if (!string.IsNullOrEmpty(str)) return str + ":" + node.LocalName; else return node.LocalName; }
string IXmlNamespaceResolver.LookupPrefix(string namespaceName) { if (!InNamespaceActiveState) { return(null); } return(nsManager.LookupPrefix(namespaceName)); }
public static string GetQName(XmlTextReader r, XmlNamespaceManager nsmgr) { string prefix = !String.IsNullOrEmpty(r.Prefix) ? r.Prefix : nsmgr.LookupPrefix(r.NamespaceURI); if (!String.IsNullOrEmpty(prefix)) return prefix + ":" + r.LocalName; else return r.LocalName; }
public static string GetQName(XmlTextReader r, XmlNamespaceManager nsmgr) { string str = !string.IsNullOrEmpty(r.Prefix) ? r.Prefix : nsmgr.LookupPrefix(r.NamespaceURI); if (!string.IsNullOrEmpty(str)) { return (str + ":" + r.LocalName); } return r.LocalName; }
public string LookupPrefix(string namespaceName) { string prefix = _nsManager.LookupPrefix(namespaceName); if (prefix == null) { prefix = _startNode.GetPrefixOfNamespaceStrict(namespaceName); } return(prefix); }
public void LoadFromXml(XmlElement el, XmlNamespaceManager nsmgr) { string pr = nsmgr.LookupPrefix(XmlSchemaUtil.WORKFLOW_NAMESPACE); if (pr != null && pr.Length > 0) pr += ":"; Name = el.GetAttribute("name"); foreach (XmlElement mel in el.SelectNodes(pr + "member", nsmgr)) { MemberDef md = new MemberDef(); md.LoadFromXml(mel, nsmgr); Members.Add(md); } }
public void LoadFromXml(XmlElement el, XmlNamespaceManager nsmgr) { string pr = nsmgr.LookupPrefix(XmlSchemaUtil.WORKFLOW_NAMESPACE); if (pr != null && pr.Length > 0) pr += ":"; Name = el.GetAttribute("name"); foreach(XmlElement v in el.SelectNodes(pr + "value", nsmgr)) { string sv = v.InnerText; //object ev = Convert.ChangeType(sv, BaseType.ValueType); EnumValues.Add(sv); } }
/// <summary> /// 对 本结点(xNode) 的 Namespace 注册 /// </summary> /// <param name="xNode">含有或继承有命名空间的结点</param> /// <param name="xNameSpaceManager">命名空间管理器</param> /// <returns>返回该 Namespace 的 prefix</returns> public static string AutoPrefix(System.Xml.XmlNode xNode, System.Xml.XmlNamespaceManager xNameSpaceManager) { string xPrefix; if (xNode.NamespaceURI == string.Empty) { return(string.Empty); } else { xPrefix = xNameSpaceManager.LookupPrefix(xNode.NamespaceURI); if (xPrefix == null || xPrefix == string.Empty) { xPrefix = "x" + xNode.GetHashCode().ToString(); xNameSpaceManager.AddNamespace(xPrefix, xNode.NamespaceURI); } return(xPrefix + (xPrefix.Length > 0 ? ":" : "")); } }
public static IDictionary<Assembly, KeyValuePair<bool, bool>> CheckQTConfigState(string devenvroot, string agentExecutable, string subpath, IEnumerable<Assembly> asms) { var agentConfigFile = Path.Combine(devenvroot, agentExecutable + ".config"); string ns = "urn:schemas-microsoft-com:asm.v1"; var x = new XmlDocument(); x.Load(agentConfigFile); var nsm = new XmlNamespaceManager(x.NameTable); var prf = nsm.LookupPrefix(ns); if (string.IsNullOrEmpty(prf)) nsm.AddNamespace(prf = "asm1", ns); var result = new Dictionary<Assembly, KeyValuePair<bool, bool>>(); foreach (var asm in asms) { var filepath = Path.Combine(subpath, Path.GetFileName(asm.Location)); bool needCleanup = junkRemover(x, asm.GetName(), ns, prf, nsm); bool entryExists = exactFinder(x, filepath, asm.GetName(), ns, prf, nsm); result.Add(asm, new KeyValuePair<bool, bool>(needCleanup, entryExists)); } return result; }
public XFormGenerator(XmlDocument skeleton, XmlNamespaceManager namespaceManager, XmlNode dataRoot, XmlNode templatesRoot, XmlNode labelsRoot, XmlNode stateRoot, XmlNode bindsRoot, XmlNode uiRoot) { xform = skeleton; xformsNamespacePrefix = namespaceManager.LookupPrefix(xformsNamespace); if(xformsNamespacePrefix == "") { xformsNamespacePrefix = "xforms"; namespaceManager.AddNamespace(xformsNamespacePrefix, xformsNamespace); } instanceGenerator = new InstanceGenerator(xform, dataRoot); instanceHandler = (Handler)instanceGenerator; templateGenerator = new InstanceGenerator(xform, templatesRoot); templateHandler = (Handler)templateGenerator; currentLabelsNode = labelsRoot; currentStateNode = stateRoot; currentBindsNode = bindsRoot; currentUINode = uiRoot; InitialiseCurrentLabelXPath(); }
public XmlValidationRule(IXmlDocumentProvider docProvider, XmlNode node, XmlNamespaceManager nsmgr) { if (node.Attributes["name"] != null) Name = node.Attributes["name"].Value; if (node.Attributes["file"] != null) File = node.Attributes["file"].Value; if (!string.IsNullOrEmpty(File)) { XmlDocument doc = docProvider.Load(File); if (doc != null) { List<ITest> tests = new List<ITest>(); string prefix = nsmgr.LookupPrefix("http://icalvalid.wikidot.com/validation"); foreach (XmlNode passNode in doc.SelectNodes("/" + prefix + ":rule/" + prefix + ":pass", nsmgr)) tests.Add(new XmlCalendarTest(passNode, nsmgr)); foreach (XmlNode failNode in doc.SelectNodes("/" + prefix + ":rule/" + prefix + ":fail", nsmgr)) tests.Add(new XmlCalendarTest(failNode, nsmgr)); Tests = tests.ToArray(); } } }
private void ReadElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName, XmlNamespaceManager manager) { if (string.IsNullOrEmpty(propertyName)) throw JsonSerializationException.Create(reader, "XmlNodeConverter cannot convert JSON with an empty property name to XML."); Dictionary<string, string> attributeNameValues = ReadAttributeElements(reader, manager); string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName); if (propertyName.StartsWith('@')) { string attributeName = propertyName.Substring(1); string attributePrefix = MiscellaneousUtils.GetPrefix(attributeName); AddAttribute(reader, document, currentNode, attributeName, manager, attributePrefix); } else if (propertyName.StartsWith('$')) { if (propertyName == JsonTypeReflector.ArrayValuesPropertyName) { propertyName = propertyName.Substring(1); elementPrefix = manager.LookupPrefix(JsonNamespaceUri); CreateElement(reader, document, currentNode, propertyName, manager, elementPrefix, attributeNameValues); } else { string attributeName = propertyName.Substring(1); string attributePrefix = manager.LookupPrefix(JsonNamespaceUri); AddAttribute(reader, document, currentNode, attributeName, manager, attributePrefix); } } else { CreateElement(reader, document, currentNode, propertyName, manager, elementPrefix, attributeNameValues); } }
public void Write(XmlWriter writer, XmlNamespaceManager namespaceManager) { XmlSerializerNamespaces namespaces; XmlSerializer serializer = new XmlSerializer(typeof(XmlSchema)); if (namespaceManager != null) { namespaces = new XmlSerializerNamespaces(); bool flag = false; if (base.Namespaces != null) { flag = (base.Namespaces.Namespaces["xs"] != null) || base.Namespaces.Namespaces.ContainsValue("http://www.w3.org/2001/XMLSchema"); } if ((!flag && (namespaceManager.LookupPrefix("http://www.w3.org/2001/XMLSchema") == null)) && (namespaceManager.LookupNamespace("xs") == null)) { namespaces.Add("xs", "http://www.w3.org/2001/XMLSchema"); } foreach (string str in namespaceManager) { if ((str != "xml") && (str != "xmlns")) { namespaces.Add(str, namespaceManager.LookupNamespace(str)); } } } else if ((base.Namespaces != null) && (base.Namespaces.Count > 0)) { Hashtable hashtable = base.Namespaces.Namespaces; if ((hashtable["xs"] == null) && !hashtable.ContainsValue("http://www.w3.org/2001/XMLSchema")) { hashtable.Add("xs", "http://www.w3.org/2001/XMLSchema"); } namespaces = base.Namespaces; } else { namespaces = new XmlSerializerNamespaces(); namespaces.Add("xs", "http://www.w3.org/2001/XMLSchema"); if ((this.targetNs != null) && (this.targetNs.Length != 0)) { namespaces.Add("tns", this.targetNs); } } serializer.Serialize(writer, this, namespaces); }
/// <summary> /// Removes Dataflow-Related Information from the Xaml(x). /// This currently includes $.Arguments-tags, $.Variables-tags, Visual Basic Settings (mva), unused clr-Imports and Namespaces. /// </summary> private void RemoveDataInformation() { // Namespaces IDictionary<string, string> nsDictionary; log.Debug("Removing XAML(X) DataInformation."); // Load DOM from file XmlDocument doc = new XmlDocument(); doc.Load(outputFile); XPathNavigator navigator = doc.CreateNavigator(); // Select first node navigator.MoveToFollowing(XPathNodeType.Element); // Namespace dictionary nsDictionary = navigator.GetNamespacesInScope(XmlNamespaceScope.All); XmlNamespaceManager namespaces = new XmlNamespaceManager(navigator.NameTable); // Add all namespaces foreach (KeyValuePair<String, String> ns in nsDictionary.ToList()) { namespaces.AddNamespace(ns.Key, ns.Value); } // Remove unused clr-Namespaces log.Debug("Removing XAML(X) unused clr-Namespaces..."); foreach (KeyValuePair<String, String> ns in nsDictionary.ToList()) { String xpath; bool clean = false; if (ns.Value.StartsWith("clr-namespace:") && !ns.Key.Equals("")) { xpath = "//" + ns.Key + ":*"; XmlNodeList nodes = null; // Only clean if unused nodes = doc.SelectNodes(xpath, namespaces); // Remove Visual Basic Settings if (ns.Value.Equals("clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities")) { clean = true; } else if (nodes.Count == 0) { clean = true; } // Cleanup if (clean) { // Remove Visual Basic Settings Nodes foreach (XmlNode n in nodes) { n.ParentNode.RemoveChild(n); } // Remove Attributes xpath = "//*[@" + ns.Key + ":*]"; nodes = doc.SelectNodes(xpath, namespaces); foreach (XmlNode node in nodes) { List<String> attributeNames = new List<string>(); // Collect (API Workaround) foreach (XmlAttribute attribute in node.Attributes) { if (attribute.NamespaceURI.Equals(ns.Value)) { attributeNames.Add(attribute.Name); } } // Remove foreach (String name in attributeNames) { node.Attributes.RemoveNamedItem(name); } } // Remove Namespace Declaration XmlElement root = doc.DocumentElement; root.Attributes.RemoveNamedItem("xmlns:" + ns.Key); } } } log.Debug("Removing XAML(X) Arguments..."); // Remove Members String prefix = namespaces.LookupPrefix("http://schemas.microsoft.com/winfx/2006/xaml"); String arguments; XmlNodeList nodeList; if (!prefix.Equals(String.Empty)) { arguments = "//" + prefix + ":Members"; nodeList = doc.SelectNodes(arguments, namespaces); foreach (XmlNode n in nodeList) { n.ParentNode.RemoveChild(n); } } // Remove Arguments arguments = "//*['Argument' = substring(name(), string-length(name())- string-length('Variables') +1)]"; nodeList = doc.SelectNodes(arguments, namespaces); foreach (XmlNode n in nodeList) { n.ParentNode.RemoveChild(n); } log.Debug("Removing XAML(X) Variables..."); // Remove Variables String variables = "//*['Variables' = substring(name(), string-length(name())- string-length('Variables') +1)]"; nodeList = doc.SelectNodes(variables, namespaces); foreach (XmlNode n in nodeList) { n.ParentNode.RemoveChild(n); } // Save File doc.Save(outputFile); log.Info("Removed XAML(X) DataInformation."); }
/// <summary> /// Produces an XPath fragment that selects ContentLocatorParts of the same type /// and containing the exact name/values this ContentLocatorPart contains. /// </summary> /// <param name="namespaceManager">namespaceManager used to generate the XPath fragment</param> private string GetExactQueryFragment(XmlNamespaceManager namespaceManager) { string corePrefix = namespaceManager.LookupPrefix(AnnotationXmlConstants.Namespaces.CoreSchemaNamespace); string prefix = namespaceManager.LookupPrefix(this.PartType.Namespace); string res = prefix == null ? "" : (prefix + ":"); res += this.PartType.Name; bool and = false; foreach (KeyValuePair<string, string> k_v in ((ICollection<KeyValuePair<string, string>>)this.NameValuePairs)) { if (and) { res += "/parent::*/" + corePrefix + ":" + AnnotationXmlConstants.Elements.Item + "["; } else { and = true; res += "/" + corePrefix + ":" + AnnotationXmlConstants.Elements.Item + "["; } res += "@" + AnnotationXmlConstants.Attributes.ItemName + "=\"" + k_v.Key + "\" and @" + AnnotationXmlConstants.Attributes.ItemValue + "=\"" + k_v.Value + "\"]"; } if (and) { res += "/parent::*"; } return res; }
public static void ApplySignboxMods(XmlDocument document, XmlNamespaceManager xmlns) { var body = (XmlElement) document.DocumentElement.SelectSingleNode("//body"); var dialog = document.CreateElement("div"); dialog.SetAttribute("data-role", "page"); dialog.SetAttribute("id", "popup"); dialog.SetAttribute("data-theme", "c"); var header = document.CreateElement("div"); header.SetAttribute("data-role", "header"); header.SetAttribute("data-position", "inline"); var headerText = document.CreateElement("h1"); headerText.InnerText = "Signature Pad"; var clearButton = document.CreateElement("a"); clearButton.SetAttribute("id", "sigPadClearButton"); clearButton.SetAttribute("href", "#"); clearButton.SetAttribute("data-icon", "refresh"); clearButton.InnerText = "Clear"; var content = document.CreateElement("div"); content.SetAttribute("data-role", "content"); var form = document.CreateElement("form"); form.SetAttribute("method", "post"); form.SetAttribute("class", "sigPad"); form.SetAttribute("action", "#"); form.SetAttribute("id", "sigDialogPad"); var sigWrapper = document.CreateElement("div"); SetElementClass(sigWrapper, "sig"); SetElementClass(sigWrapper, "sigWrapper"); var sigCanvas = document.CreateElement("canvas"); SetElementClass(sigCanvas, "pad"); sigCanvas.SetAttribute("height", "200"); sigCanvas.SetAttribute("width", "500"); var sigInput = document.CreateElement("input"); sigInput.SetAttribute("type", "hidden"); sigInput.SetAttribute("name", "output"); sigInput.SetAttribute("class", "output"); var footer = document.CreateElement("div"); footer.SetAttribute("data-role", "footer"); var footerText = document.CreateElement("h4"); footerText.InnerText = ""; header.AppendChild(headerText); header.AppendChild(clearButton); sigWrapper.AppendChild(sigCanvas); sigWrapper.AppendChild(sigInput); form.AppendChild(sigWrapper); content.AppendChild(form); footer.AppendChild(footerText); dialog.AppendChild(header); dialog.AppendChild(content); dialog.AppendChild(footer); body.AppendChild(dialog); var ns = xmlns.LookupPrefix(@"http://schemas.microsoft.com/office/infopath/2003"); var ctrlIdAttrName = ns + ":CtrlId"; var signpads = document.SelectNodes(String.Format("//object[@{0}:xctname='inkpicture']", ns), xmlns); foreach ( XmlElement signpad in signpads ) { /* <a class="signLink" href="#popup" id="CTRL88_5" data-role="button" data-rel="dialog" data-transition="none"> <input type="hidden" class="output" /> <img class="preview"/> </a */ var controlName = signpad.Attributes[ctrlIdAttrName].Value; var styleAttr = signpad.Attributes["style"]; var style = new StyleAttributeString(styleAttr); var parent = (XmlElement) signpad.ParentNode; if ( parent.LocalName == "if" ) parent = (XmlElement) parent.ParentNode; var button = document.CreateElement("a"); button.SetAttribute("class", "signLink"); button.SetAttribute("href", "#popup"); button.SetAttribute("id", controlName); //button.SetAttribute("data-role", "button"); button.SetAttribute("data-rel", "dialog"); button.SetAttribute("data-transition", "none"); //button.InnerText = "Signature pad"; var input = document.CreateElement("input"); input.SetAttribute("type", "hidden"); input.SetAttribute("class", "output"); var img = document.CreateElement("img"); img.SetAttribute("class", "preview"); img.SetAttribute("src", "sign-here.gif"); if ( style.Properties.ContainsKey("width") ) { var newStyle = new StyleAttributeString(); newStyle.AssignProperty("width", style.Properties["width"]); img.SetAttribute("style", newStyle.ToString()); } button.AppendChild(input); button.AppendChild(img); parent.AppendChild(button); } }
public void LookupPrefix () { // This test should use an empty nametable. XmlNamespaceManager nsmgr = new XmlNamespaceManager (new NameTable ()); nsmgr.NameTable.Add ("urn:hoge"); nsmgr.NameTable.Add ("urn:fuga"); nsmgr.AddNamespace (string.Empty, "urn:hoge"); Assert.IsNull (nsmgr.LookupPrefix ("urn:fuga")); Assert.AreEqual (String.Empty, nsmgr.LookupPrefix ("urn:hoge")); }
string IXmlNamespaceResolver.LookupPrefix(string namespaceName) { return(_namespaceManager.LookupPrefix(namespaceName)); }
private string GetLocation() { string path = null; this.doc = this.view.Model.Document; this.nsmgr = new XmlNamespaceManager(doc.NameTable); XmlTreeNode node = this.view.SelectedNode as XmlTreeNode; if (node != null) { XmlNode xnode = node.Node; if (xnode != null) { XmlNode nsctx = xnode; if (nsctx.NodeType != XmlNodeType.Element) { if (nsctx.NodeType == XmlNodeType.Attribute) { nsctx = ((XmlAttribute)nsctx).OwnerElement; } else { nsctx = nsctx.ParentNode; } } if (nsctx == null || nsctx == this.doc) nsctx = this.doc.DocumentElement; foreach (XmlAttribute a in nsctx.SelectNodes("namespace::*")) { string prefix = (a.Prefix == "xmlns") ? a.LocalName : ""; if (!string.IsNullOrEmpty(prefix)) { string ns = a.Value; if (nsmgr.LookupPrefix(ns) == null) { nsmgr.AddNamespace(prefix, ns); } } } foreach (XmlElement child in nsctx.SelectNodes("//*[namespace-uri(.) != '']")) { string uri = child.NamespaceURI; if (nsmgr.LookupPrefix(uri) == null) { string prefix = child.Prefix; if (!string.IsNullOrEmpty(prefix)) { nsmgr.AddNamespace(prefix, uri); } } } XPathGenerator gen = new XPathGenerator(); path = gen.GetXPath(xnode, nsmgr); } } return path; }
private static void ApplyTextboxMods(XmlDocument document, XmlNamespaceManager xmlns) { //<input type="text" hideFocus="1" class="xdTextBox" var ns = xmlns.LookupPrefix(@"http://schemas.microsoft.com/office/infopath/2003"); var ctrlIdAttrName = ns + ":CtrlId"; var textboxes = document.SelectNodes(String.Format("//span[@{0}:xctname='PlainText']", ns), xmlns); foreach ( XmlElement textbox in textboxes ) { var controlName = textbox.Attributes[ctrlIdAttrName].Value; var styleAttr = textbox.Attributes["style"]; var parent = ((XmlElement) textbox.ParentNode); StyleAttributeString style = null; if ( styleAttr != null ) style = new StyleAttributeString(styleAttr.Value); XmlElement inputField = null; if ( style != null && style.Properties.ContainsKey("overflow-y") ) { inputField = document.CreateElement("textarea"); style.AssignProperty("height", "100%"); style.AssignProperty("min-height", "36px"); SetElementClass(parent, "textarea-container"); } else { inputField = document.CreateElement("input"); if ( style != null && style.Properties.ContainsKey("height") ) { style.Properties.Remove("height"); } } inputField.SetAttribute("id", controlName); inputField.SetAttribute("name", controlName); inputField.SetAttribute("type", "text"); if ( style != null ) inputField.SetAttribute("style", style.ToString()); parent.AppendChild(inputField); } }
private static void ApplyRadioButtonMods(XmlDocument document, XmlNamespaceManager xmlns) { var radioButtons = document.SelectNodes("//input[@type='radio']"); var ns = xmlns.LookupPrefix(@"http://schemas.microsoft.com/office/infopath/2003"); foreach ( XmlElement button in radioButtons ) { var controlName = button.Attributes[ns + ":CtrlId"].Value; string value = button.Attributes[ns + ":onValue"].Value; string bindingProp = button.Attributes[ns + ":binding"].Value; button.SetAttribute("value", value); button.SetAttribute("name", bindingProp); button.SetAttribute("id", controlName); XmlElement parent = ( (XmlElement) button.ParentNode ); XmlElement label = document.CreateElement("label"); label.SetAttribute("for", controlName); parent.AppendChild(label); } }
private static void ApplyCheckboxMods(XmlDocument document, XmlNamespaceManager xmlns) { var checkboxes = document.SelectNodes("//input[@type='checkbox']"); var ns = xmlns.LookupPrefix(@"http://schemas.microsoft.com/office/infopath/2003"); var ctrlIdAttrName = ns + ":CtrlId"; foreach (XmlElement checkbox in checkboxes) { var controlName = checkbox.Attributes[ctrlIdAttrName].Value; string onValue = checkbox.Attributes[ns + ":onValue"].Value; string offValue = checkbox.Attributes[ns + ":offValue"].Value; XmlElement parent = ( (XmlElement) checkbox.ParentNode ); parent.SetAttribute("class", "checkbox-wrapper"); XmlElement select = document.CreateElement("select"); select.SetAttribute("id", controlName); select.SetAttribute("name", controlName); select.SetAttribute("data-role", "slider"); XmlElement optionYes = document.CreateElement("option"); optionYes.SetAttribute("value", onValue); optionYes.AppendChild(document.CreateTextNode("|")); XmlElement optionNo = document.CreateElement("option"); optionNo.SetAttribute("value", offValue); optionNo.AppendChild(document.CreateTextNode("O")); select.AppendChild(optionNo); select.AppendChild(optionYes); parent.AppendChild(select); } }
public void AtomizedLookup () { if (DateTime.Now.Year == 0) suffix = String.Empty; XmlNamespaceManager nsmgr = new XmlNamespaceManager (new NameTable ()); nsmgr.AddNamespace ("foo", "urn:foo"); Assert.IsNotNull (nsmgr.LookupPrefix ("urn:foo")); // FIXME: This returns registered URI inconsistently. // Assert.IsNull (nsmgr.LookupPrefix ("urn:f" + suffix), "It is not atomized and thus should be failed"); }
private string ResolveFullName(IXmlNode node, XmlNamespaceManager manager) { string prefix = (node.NamespaceUri == null || (node.LocalName == "xmlns" && node.NamespaceUri == "http://www.w3.org/2000/xmlns/")) ? null : manager.LookupPrefix(node.NamespaceUri); if (!string.IsNullOrEmpty(prefix)) { return prefix + ":" + XmlConvert.DecodeName(node.LocalName); } else { return XmlConvert.DecodeName(node.LocalName); } }
private string ResolveFullName(IXmlNode node, XmlNamespaceManager manager) { string prefix = (node.NamespaceURI == null || (node.LocalName == "xmlns" && node.NamespaceURI == "http://www.w3.org/2000/xmlns/")) ? null : manager.LookupPrefix(node.NamespaceURI); if (!string.IsNullOrEmpty(prefix)) return prefix + ":" + node.LocalName; else return node.LocalName; }
/// <summary> /// Produces an XPath fragment that selects for ContentLocatorParts with an anchor that /// intersects with the range specified by this ContentLocatorPart. /// </summary> /// <param name="namespaceManager">namespace manager used to look up prefixes</param> private string GetOverlapQueryFragment(XmlNamespaceManager namespaceManager) { string corePrefix = namespaceManager.LookupPrefix(AnnotationXmlConstants.Namespaces.CoreSchemaNamespace); string prefix = namespaceManager.LookupPrefix(this.PartType.Namespace); string res = prefix == null ? "" : (prefix + ":"); res += TextSelectionProcessor.CharacterRangeElementName.Name + "/" + corePrefix + ":"+AnnotationXmlConstants.Elements.Item; int startOffset; int endOffset; TextSelectionProcessor.GetMaxMinLocatorPartValues(this, out startOffset, out endOffset); string startStr = startOffset.ToString(NumberFormatInfo.InvariantInfo); string endStr = endOffset.ToString(NumberFormatInfo.InvariantInfo); // Note: this will never match if offsetStr == 0. Which makes sense - there // is no content to get anchors for. res += "[starts-with(@" + AnnotationXmlConstants.Attributes.ItemName + ", \"" + TextSelectionProcessor.SegmentAttribute + "\") and " + " ((substring-before(@" + AnnotationXmlConstants.Attributes.ItemValue + ",\",\") >= " + startStr + " and substring-before(@" + AnnotationXmlConstants.Attributes.ItemValue + ",\",\") <= " + endStr + ") or " + " (substring-before(@" + AnnotationXmlConstants.Attributes.ItemValue + ",\",\") < " + startStr + " and substring-after(@" + AnnotationXmlConstants.Attributes.ItemValue + ",\",\") >= " + startStr + "))]"; return res; }
// Note that this must be done *before* filtering nodes out // by context node list. private void FillMissingPrefixes (XmlNode n, XmlNamespaceManager nsmgr, ArrayList tmpList) { if (n.Prefix.Length == 0 && propagatedNss != null) { foreach (DictionaryEntry de in propagatedNss) if ((string) de.Value == n.NamespaceURI) { n.Prefix = (string) de.Key; break; } } if (n.NodeType == XmlNodeType.Element && ((XmlElement) n).HasAttributes) { foreach (XmlAttribute a in n.Attributes) if (a.NamespaceURI == "http://www.w3.org/2000/xmlns/") nsmgr.AddNamespace (a.Prefix.Length == 0 ? String.Empty : a.LocalName, a.Value); nsmgr.PushScope (); } if (n.NamespaceURI.Length > 0 && nsmgr.LookupPrefix (n.NamespaceURI) == null) tmpList.Add (CreateXmlns (n)); if (n.NodeType == XmlNodeType.Element && ((XmlElement) n).HasAttributes) { foreach (XmlAttribute a in n.Attributes) if (a.NamespaceURI.Length > 0 && nsmgr.LookupNamespace (a.Prefix) == null) tmpList.Add (CreateXmlns (a)); } foreach (XmlAttribute a in tmpList) ((XmlElement) n).SetAttributeNode (a); tmpList.Clear (); if (n.HasChildNodes) { for (XmlNode c = n.FirstChild; c != null; c = c.NextSibling) if (c.NodeType == XmlNodeType.Element) FillMissingPrefixes (c, nsmgr, tmpList); } nsmgr.PopScope (); }
public void LoadXml(XmlElement rootNode, XmlNamespaceManager nsmgr) { string pr = nsmgr.LookupPrefix(XmlSchemaUtil.WORKFLOW_NAMESPACE); pr = (pr != null && pr.Length > 0) ? pr + ":" : ""; foreach (XmlElement el in rootNode.ChildNodes) { if (el.LocalName == "struct") { StructDef sd = new StructDef(); sd.LoadFromXml(el, nsmgr); AddType(sd); } else if (el.LocalName == "enum") { EnumDef ed = new EnumDef(); ed.LoadFromXml(el, nsmgr); AddType(ed); } else throw new Exception("Unexpected node: " + el.Name); } }
private Dictionary<string, string> ReadAttributeElements(JsonReader reader, XmlNamespaceManager manager) { Dictionary<string, string> attributeNameValues = new Dictionary<string, string>(); bool finishedAttributes = false; bool finishedElement = false; // a string token means the element only has a single text child if (reader.TokenType != JsonToken.String && reader.TokenType != JsonToken.Null && reader.TokenType != JsonToken.Boolean && reader.TokenType != JsonToken.Integer && reader.TokenType != JsonToken.Float && reader.TokenType != JsonToken.Date && reader.TokenType != JsonToken.StartConstructor) { // read properties until first non-attribute is encountered while (!finishedAttributes && !finishedElement && reader.Read()) { switch (reader.TokenType) { case JsonToken.PropertyName: string attributeName = reader.Value.ToString(); if (!string.IsNullOrEmpty(attributeName)) { char firstChar = attributeName[0]; string attributeValue; switch (firstChar) { case '@': attributeName = attributeName.Substring(1); reader.Read(); attributeValue = ConvertTokenToXmlValue(reader); attributeNameValues.Add(attributeName, attributeValue); string namespacePrefix; if (IsNamespaceAttribute(attributeName, out namespacePrefix)) { manager.AddNamespace(namespacePrefix, attributeValue); } break; case '$': attributeName = attributeName.Substring(1); reader.Read(); attributeValue = reader.Value.ToString(); // check that JsonNamespaceUri is in scope // if it isn't then add it to document and namespace manager string jsonPrefix = manager.LookupPrefix(JsonNamespaceUri); if (jsonPrefix == null) { // ensure that the prefix used is free int? i = null; while (manager.LookupNamespace("json" + i) != null) { i = i.GetValueOrDefault() + 1; } jsonPrefix = "json" + i; attributeNameValues.Add("xmlns:" + jsonPrefix, JsonNamespaceUri); manager.AddNamespace(jsonPrefix, JsonNamespaceUri); } attributeNameValues.Add(jsonPrefix + ":" + attributeName, attributeValue); break; default: finishedAttributes = true; break; } } else { finishedAttributes = true; } break; case JsonToken.EndObject: finishedElement = true; break; default: throw new JsonSerializationException("Unexpected JsonToken: " + reader.TokenType); } } } return attributeNameValues; }
public void AddPushPopRemove () { XmlNamespaceManager nsmgr = new XmlNamespaceManager (new NameTable ()); string ns = nsmgr.NameTable.Add ("urn:foo"); nsmgr.AddNamespace ("foo", ns); Assert.AreEqual ("foo", nsmgr.LookupPrefix (ns)); nsmgr.PushScope (); Assert.AreEqual ("foo", nsmgr.LookupPrefix (ns)); nsmgr.PopScope (); Assert.AreEqual ("foo", nsmgr.LookupPrefix (ns)); nsmgr.RemoveNamespace ("foo", ns); Assert.IsNull (nsmgr.LookupPrefix (ns)); }