public override void WriteEndAttribute() { if (_catchNs) { _catchNs = false; _ns = _nsmgr.NameTable.Get(_ns); if (_prefix != null) { if (_forbiddenNs == _ns) { // If xmlns:ns="the-ns" where namespace is given return; } } else if (_nsmgr.LookupPrefix(_ns) != null) { // If xmlns="the-ns" whrer namespace is given return; } base.WriteStartAttribute("xmlns", _prefix, "http://www.w3.org/2000/xmlns/"); base.WriteString(_ns); } base.WriteEndAttribute(); }
/// <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); }
/// <summary> /// Determines the namespace we should look for OpenSearch elements in when parsing the documents. /// </summary> /// <param name="file"> /// The source file. /// </param> /// <returns> /// The namespace to look for elements in. /// </returns> private static string DetermineOpenSearchElementNamespace(string file) { XmlDocument doc = new XmlDocument(); doc.Load(file); // Figure out what namepsaces are in the document. XmlNamespaceManager namespaceManager = PopulateNamespaceManager(doc); // An OpenSearch document can both the mozilla namespace and the opensearch namespace, // so we figure if it contains either... bool isMozillaSearch = (namespaceManager.LookupPrefix("http://www.mozilla.org/2006/browser/search/") != null); bool isOpenSearch = (namespaceManager.LookupPrefix("http://a9.com/-/spec/opensearch/1.1/") != null); // ...and then apply a little logic. if (isOpenSearch) { return("os"); } if (isMozillaSearch && !isOpenSearch) { return("default"); } throw new Exception("Unable to determine OpenSearch plugin type."); }
// Token: 0x06006332 RID: 25394 RVA: 0x001BE260 File Offset: 0x001BC460 private string GetOverlapQueryFragment(XmlNamespaceManager namespaceManager) { string text = namespaceManager.LookupPrefix("http://schemas.microsoft.com/windows/annotations/2003/11/core"); string text2 = namespaceManager.LookupPrefix(this.PartType.Namespace); string text3 = (text2 == null) ? "" : (text2 + ":"); text3 = string.Concat(new string[] { text3, TextSelectionProcessor.CharacterRangeElementName.Name, "/", text, ":Item" }); int num; int num2; TextSelectionProcessor.GetMaxMinLocatorPartValues(this, out num, out num2); string text4 = num.ToString(NumberFormatInfo.InvariantInfo); string text5 = num2.ToString(NumberFormatInfo.InvariantInfo); return(string.Concat(new string[] { text3, "[starts-with(@Name, \"Segment\") and ((substring-before(@Value,\",\") >= ", text4, " and substring-before(@Value,\",\") <= ", text5, ") or (substring-before(@Value,\",\") < ", text4, " and substring-after(@Value,\",\") >= ", text4, "))]" })); }
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> strs = this.ReadAttributeElements(reader, manager); string prefix = MiscellaneousUtils.GetPrefix(propertyName); if (propertyName.StartsWith('@')) { string str = propertyName.Substring(1); string prefix1 = MiscellaneousUtils.GetPrefix(str); XmlNodeConverter.AddAttribute(reader, document, currentNode, str, manager, prefix1); return; } if (propertyName.StartsWith('$')) { if (propertyName == "$values") { propertyName = propertyName.Substring(1); prefix = manager.LookupPrefix("http://james.newtonking.com/projects/json"); this.CreateElement(reader, document, currentNode, propertyName, manager, prefix, strs); return; } if (propertyName == "$id" || propertyName == "$ref" || propertyName == "$type" || propertyName == "$value") { string str1 = propertyName.Substring(1); string str2 = manager.LookupPrefix("http://james.newtonking.com/projects/json"); XmlNodeConverter.AddAttribute(reader, document, currentNode, str1, manager, str2); return; } } this.CreateElement(reader, document, currentNode, propertyName, manager, prefix, strs); }
IEnumerable <CodeMemberField> GetCodeMemberFields(XmlNode root, XmlNamespaceManager nsmgr) { var xPrefix = nsmgr.LookupPrefix(XamlParser.X2006Uri) ?? nsmgr.LookupPrefix(XamlParser.X2009Uri); if (xPrefix == null) { yield break; } XmlNodeList names = root.SelectNodes( "//*[@" + xPrefix + ":Name" + "][not(ancestor:: __f__:DataTemplate) and not(ancestor:: __f__:ControlTemplate) and not(ancestor:: __f__:Style) and not(ancestor:: __f__:VisualStateManager.VisualStateGroups)]", nsmgr); foreach (XmlNode node in names) { var name = GetAttributeValue(node, "Name", XamlParser.X2006Uri, XamlParser.X2009Uri); var typeArguments = GetAttributeValue(node, "TypeArguments", XamlParser.X2006Uri, XamlParser.X2009Uri); var fieldModifier = GetAttributeValue(node, "FieldModifier", XamlParser.X2006Uri, XamlParser.X2009Uri); var xmlType = new XmlType(node.NamespaceURI, node.LocalName, typeArguments != null ? TypeArgumentsParser.ParseExpression(typeArguments, nsmgr, null) : null); var access = MemberAttributes.Private; if (fieldModifier != null) { switch (fieldModifier.ToLowerInvariant()) { default: case "private": access = MemberAttributes.Private; break; case "public": access = MemberAttributes.Public; break; case "protected": access = MemberAttributes.Family; break; case "internal": case "notpublic": //WPF syntax access = MemberAttributes.Assembly; break; } } yield return(new CodeMemberField { Name = name, Type = GetType(xmlType, node.GetNamespaceOfPrefix), Attributes = access, CustomAttributes = { GeneratedCodeAttrDecl } }); } }
private ICollection <FileInfo> GetFlashLinks() { List <FileInfo> attachments = new List <FileInfo>(); String xml = this.document.WordOpenXML; XmlDocument docopenXml = new XmlDocument(); docopenXml.LoadXml(xml); XmlNamespaceManager manager = new XmlNamespaceManager(docopenXml.NameTable); string prefix = manager.LookupPrefix("http://schemas.microsoft.com/office/2006/activeX"); String snamespace = manager.LookupNamespace("ax"); if (prefix == null) { prefix = "ax"; manager.AddNamespace(prefix, "http://schemas.microsoft.com/office/2006/activeX"); } prefix = manager.LookupPrefix("http://schemas.microsoft.com/office/2006/xmlPackage"); if (prefix == null) { prefix = "pkg"; manager.AddNamespace(prefix, "http://schemas.microsoft.com/office/2006/xmlPackage"); } XmlNodeList nodes = docopenXml.SelectNodes("//pkg:xmlData/ax:ocx/ax:ocxPr", manager); foreach (XmlNode node in nodes) { if (node is XmlElement) { XmlElement ocxPr = (XmlElement)node; String nameatt = ocxPr.GetAttribute("name", "http://schemas.microsoft.com/office/2006/activeX"); if (nameatt != null && (nameatt.ToLower().Equals("src") || nameatt.ToLower().Equals("movie"))) { String value = ocxPr.GetAttribute("value", "http://schemas.microsoft.com/office/2006/activeX"); if (value != null && value.ToLower().EndsWith(".swf")) { String archivo = value; System.Uri basepath = new System.Uri(this.document.Path + "\\"); System.Uri filepath = new System.Uri(basepath, archivo); if (filepath.IsFile) { FileInfo farchivo = new FileInfo(filepath.LocalPath); if (farchivo.Extension.IndexOf(".") != -1) { if (!attachments.Contains(farchivo)) { attachments.Add(farchivo); } } } } } } } return(attachments); }
private XmlElement CreateQualifyingPropertiesNode(SignedXml signedXml, XmlDocument document) { var result = document.CreateElement("QualifyingProperties", XADES_NAMESPACE_URI); result.Prefix = xmlNamespaceManager.LookupPrefix(XADES_NAMESPACE_URI); result.SetAttribute("Target", "#" + signedXml.Signature.Id); return(result); }
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")); }
private void SortRequest(TagTestItem spec, AttrBroadcasterFilter connection, CreatorIssuer template, string pred2, XmlNamespaceManager connection3) { //Discarded unreachable code: IL_0002 //IL_0003: Incompatible stack heights: 0 vs 1 if (SetterTest.StartReader(pred2)) { throw StrategyError.PatchComposer(spec, "XmlNodeConverter cannot convert JSON with an empty property name to XML."); } Dictionary <string, string> token = null; string asset = null; if (!_0005()) { token = (CheckIterator(spec) ? DisableIterator(spec, connection3) : null); asset = CustomerListAnnotation.CountIssuer(pred2); if (pred2.ExcludeReader('@')) { string text = pred2.Substring(1); string reference = CustomerListAnnotation.CountIssuer(text); PublishRequest(spec, connection, template, pred2, text, connection3, reference); return; } if (pred2.ExcludeReader('$')) { switch (pred2) { case "$values": pred2 = pred2.Substring(1); asset = connection3.LookupPrefix("http://james.newtonking.com/projects/json"); CallRequest(spec, connection, template, pred2, connection3, asset, token); return; case "$id": case "$ref": case "$type": case "$value": { string v = pred2.Substring(1); string reference2 = connection3.LookupPrefix("http://james.newtonking.com/projects/json"); PublishRequest(spec, connection, template, pred2, v, connection3, reference2); return; } } } } else if (CheckIterator(spec)) { spec.SortError(); } CallRequest(spec, connection, template, pred2, connection3, asset, token); }
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)); }
static private bool EnsureXmlDocument() { if (_XmlDocument == null) { _XmlDocument = null; _Nsmgr = null; _Prefix = null; foreach (string id in _LanguageIdentifiers) { _XmlDocument = _XmlDocumentProvider.Load("languages/" + id + ".xml"); if (_XmlDocument != null) { _CurrentLanguageIdentifier = id; break; } } if (_XmlDocument != null) { _Nsmgr = new XmlNamespaceManager(_XmlDocument.NameTable); _Prefix = _Nsmgr.LookupPrefix("http://icalvalid.wikidot.com/validation"); if (_Prefix == null) { _Nsmgr.AddNamespace("v", "http://icalvalid.wikidot.com/validation"); _Prefix = "v"; } } } return(_XmlDocument != null); }
public XmlElement GetXml(XmlNamespaceManager namespaceMgr) { //if (propertyModified) { // It looks MS.NET returns element which comes from new XmlDocument every time XmlElement oldElement = element; XmlDocument doc = new XmlDocument(namespaceMgr.NameTable); var prefix = namespaceMgr.LookupPrefix(XmlSignature.NamespaceURI); element = doc.CreateElement(prefix, XmlSignature.ElementNames.Object, XmlSignature.NamespaceURI); foreach (XmlAttribute attribute in oldElement.Attributes) { switch (attribute.Name) { case XmlSignature.AttributeNames.Id: case XmlSignature.AttributeNames.Encoding: case XmlSignature.AttributeNames.MimeType: element.SetAttribute(attribute.Name, attribute.Value); break; } } foreach (XmlNode n in oldElement.ChildNodes) { element.AppendChild(doc.ImportNode(n, true)); } //} return(element); }
/// <summary> /// Given an existing /// </summary> /// <param name="hipsNamespace">Namespace where covert text will be stored</param> /// <param name="docPartText">A reader that will provide the XML of the Document part</param> /// <param name="covertText">Text to be inserted</param> /// <returns>Returns a DocumentFormat.OpenXml.Wordprocessing.Document object that has covert string inserted</returns> private static wp.Document generateDocBodyXML(string hipsNamespace, TextReader docPartText, string covertText) { NameTable nt = new NameTable(); // Manage namespaces to perform XPath queries. XmlNamespaceManager nsManager = new XmlNamespaceManager(nt); nsManager.AddNamespace("w", wordmlNamespace); nsManager.AddNamespace("hips", hipsNamespace); nsManager.AddNamespace("mc", mcNamespace); XmlDocument xdoc = new XmlDocument(nt); xdoc.Load(docPartText); XmlNode mcIgnorable = xdoc.DocumentElement.Attributes.GetNamedItem("Ignorable", mcNamespace) ?? xdoc.CreateAttribute("mc", "Ignorable", mcNamespace); mcIgnorable.Value = (mcIgnorable.Value + " " + nsManager.LookupPrefix(hipsNamespace)).TrimStart(); xdoc.DocumentElement.Attributes.SetNamedItem(mcIgnorable); XmlNode hiContent = xdoc.CreateNode(XmlNodeType.Element, "hips", "t", hipsNamespace); hiContent.InnerText = covertText; XmlNode firstParagraph = xdoc.SelectSingleNode("/w:document[1]/w:body[1]/w:p[1]", nsManager); //get first paragraph in document element firstParagraph.AppendChild(hiContent); return(new wp.Document(xdoc.InnerXml)); }
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(); } } }
// 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(); }
/// <summary> /// Deserializes the alias. /// </summary> /// <param name="xmlReader">The XML text reader.</param> /// <param name="xmlStack">The XML stack.</param> private void DeserializeAlias(XmlReader xmlReader, Stack <string> xmlStack) { string idAttribute = xmlReader.GetAttribute(XmlConstants.Id); // id Guid id = Guid.Empty; if (idAttribute == null || !Guid.TryParse(idAttribute, out id)) { ThrowXmlException("AliasMap does not contain a valid id.", xmlReader); } // type string aliasType = xmlReader.GetAttribute(XmlConstants.Type); string nsAlias = xmlReader.NamespaceURI + ":" + xmlReader.LocalName; var entry = new Tuple <Guid, string>(id, aliasType); _aliasMap[xmlReader.NamespaceURI + ":" + xmlReader.LocalName] = entry; // Add dictionary entry to lookup by short alias string prefix = _namespaceManager.LookupPrefix(xmlReader.NamespaceURI); if (string.IsNullOrEmpty(prefix)) { _aliasMap[xmlReader.LocalName] = entry; } else { _aliasMap[prefix + ":" + xmlReader.LocalName] = entry; } }
public static Response NewResponse(XmlDocument responseDocument) { XmlNamespaceManager nsmgr = XmlUtil.NamespaceManager; XmlNode body = responseDocument.SelectSingleNode(apiResponseSelector, nsmgr); XmlNode firstChild = body.FirstChild; if (firstChild == null) { throw new Exception("invalid server response"); } String responseLocal = firstChild.LocalName; String responseUriPrefix = nsmgr.LookupPrefix(nsmgr.NameTable.Get(body.FirstChild.NamespaceURI)); String responseName = responseUriPrefix + ":" + responseLocal; if (!classFactories.ContainsKey(responseName)) { throw new Exception("Unknown response: " + responseName); } IResponseClassFactory rcf = (IResponseClassFactory)classFactories[responseName]; return(rcf.NewResponse(firstChild)); }
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 void LoadSchema(string uri, string url) { if (this.XmlResolver == null) { return; } if (SchemaInfo.TargetNamespaces.ContainsKey(uri) && nsManager.LookupPrefix(uri) != null) { return; } SchemaInfo schemaInfo = null; if (SchemaCollection != null) { schemaInfo = SchemaCollection.GetSchemaInfo(uri); } if (schemaInfo != null) { if (schemaInfo.SchemaType != SchemaType.XSD) { throw new XmlException(Res.Xml_MultipleValidaitonTypes, string.Empty, this.PositionInfo.LineNumber, this.PositionInfo.LinePosition); } SchemaInfo.Add(schemaInfo, EventHandler); return; } if (url != null) { LoadSchemaFromLocation(uri, url); } }
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"); foreach (XmlNode rule in node.SelectNodes(prefix + ":rule", nsmgr)) { rules.Add(new XmlValidationRule(docProvider, rule, nsmgr)); } Rules = rules.ToArray(); }
/// <summary> /// Иниализация операции переноса на основании метаописания уровня иерархии /// </summary> /// <param name="treeLevel">Описатель уровня иерархии</param> internal XXTreeNodeDrag(XTreeLevelInfo treeLevel, XMetadataManager manager) { m_xmlNSManager = treeLevel.NamespaceManager; string metaname = treeLevel.Xml.GetAttribute("node-drag", m_sExtensionNamespace); if (string.IsNullOrEmpty(metaname)) { metaname = treeLevel.TreeInfo.Xml.GetAttribute("node-drag", m_sExtensionNamespace); } if (!string.IsNullOrEmpty(metaname)) { string prefix = m_xmlNSManager.LookupPrefix(m_sExtensionNamespace); m_xmlNodeDrag = manager.SelectSingleNode(prefix + ":node-drag[@n=\"" + metaname + "\"]") as XmlElement; } if (m_xmlNodeDrag == null) { m_bIsEmpty = true; } else { m_bIsEmpty = false; string sValue = m_xmlNodeDrag.GetAttribute("cache-for"); if (sValue.Length > 0) { m_cacheMode = XTreeMenuCacheModeParser.Parse(sValue); } else { m_cacheMode = XTreeMenuCacheMode.Unknow; } } }
protected override void OnWriteStartEnvelope(XmlDictionaryWriter writer) { writer.WriteStartElement(_xmlNamespaceManager.LookupPrefix(Namespaces.WSDL_NS), "definitions", Namespaces.WSDL_NS); // Soap11 if (Version == MessageVersion.Soap11 || Version == MessageVersion.Soap11WSAddressingAugust2004 || Version == MessageVersion.Soap11WSAddressingAugust2004) { WriteXmlnsAttribute(writer, Namespaces.SOAP11_NS); } // Soap12 else if (Version == MessageVersion.Soap12WSAddressing10 || Version == MessageVersion.Soap12WSAddressingAugust2004) { WriteXmlnsAttribute(writer, Namespaces.SOAP12_NS); } else { throw new ArgumentOutOfRangeException(nameof(Version), "Unsupported MessageVersion encountered while writing envelope."); } _xmlNamespaceManager.AddNamespace("tns", _service.Contracts.First().Namespace); WriteXmlnsAttribute(writer, _service.Contracts.First().Namespace); WriteXmlnsAttribute(writer, Namespaces.XMLNS_XSD); WriteXmlnsAttribute(writer, Namespaces.HTTP_NS); WriteXmlnsAttribute(writer, Namespaces.MSC_NS); WriteXmlnsAttribute(writer, Namespaces.WSP_NS); WriteXmlnsAttribute(writer, Namespaces.WSU_NS); WriteXmlnsAttribute(writer, Namespaces.WSAM_NS); writer.WriteAttributeString("targetNamespace", _service.Contracts.First().Namespace); writer.WriteAttributeString("name", _service.ServiceType.Name); WriteXmlnsAttribute(writer, Namespaces.WSDL_NS); if (_binding != null && _binding.HasBasicAuth()) { writer.WriteStartElement("Policy", Namespaces.WSP_NS); writer.WriteAttributeString("Id", _xmlNamespaceManager.LookupPrefix(Namespaces.WSU_NS), $"{_binding.Name}_{_service.Contracts.First().Name}_policy"); writer.WriteStartElement("ExactlyOne", Namespaces.WSP_NS); writer.WriteStartElement("All", Namespaces.WSP_NS); writer.WriteStartElement("BasicAuthentication", Namespaces.HTTP_NS); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndElement(); } }
public void ShouldFillNamespaceManager() { XmlNamespaceManager mgr = Convert.ToNamespaceContext(new Dictionary <string, string> { { "foo", "bar" } }); Assert.AreEqual("foo", mgr.LookupPrefix("bar")); Assert.AreEqual("bar", mgr.LookupNamespace("foo")); }
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 SetNamespace(string ns) { string?prefix = _namespaces.LookupPrefix(ns); if (prefix == null || prefix.Length == 0) { prefix = "xg" + (_nextPrefix++).ToString(NumberFormatInfo.InvariantInfo); Namespaces.AddNamespace(prefix, ns); } return(prefix); }
/// <summary> /// Gets the prefix. /// </summary> /// <param name="namespaceManager">The namespace manager.</param> /// <param name="uri">The URI.</param> /// <param name="default">The @default prefix.</param> /// <returns>The prefix to use for namespace uri.</returns> private static string GetPrefix(XmlNamespaceManager namespaceManager, string uri, string @default) { string prefix = namespaceManager.LookupPrefix(uri); if (String.IsNullOrEmpty(prefix)) { namespaceManager.AddNamespace(prefix = @default, uri); } return(prefix); }
public override void LoadFromXml(XmlElement el, XmlNamespaceManager nsmgr) { base.LoadFromXml(el, nsmgr); string pr = nsmgr.LookupPrefix(XmlSchemaUtil.WORKFLOW_NAMESPACE); if (pr != null && pr.Length > 0) { pr += ":"; } VariableDir = (VariableDef.Dir)Enum.Parse(typeof(VariableDef.Dir), el.GetAttribute("dir")); DefaultValueExpr = XmlSchemaUtil.GetXmlElementText(el, pr + "defaultValue", nsmgr); }
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); } }
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 + ":" + XmlConvert.DecodeName(node.LocalName)); } return(XmlConvert.DecodeName(node.LocalName)); }
// Test adding items to a namespace manager. public void TestXmlNamespaceManagerAdd() { NameTable table = new NameTable(); XmlNamespaceManager ns = new XmlNamespaceManager(table); // Test exception behaviour. try { ns.AddNamespace(null, "uri"); Fail("Add (1)"); } catch(ArgumentNullException) { // Success } try { ns.AddNamespace("prefix", null); Fail("Add (2)"); } catch(ArgumentNullException) { // Success } try { ns.AddNamespace("xml", "uri"); Fail("Add (3)"); } catch(ArgumentException) { // Success } try { ns.AddNamespace("xmlns", "uri"); Fail("Add (4)"); } catch(ArgumentException) { // Success } try { // Work around intern'ed string handling in the engine. ns.AddNamespace(String.Concat("xml", "ns"), "uri"); Fail("Add (5)"); } catch(ArgumentException) { // Success } // Try changing the default namespace. ns.AddNamespace("", "defuri"); AssertEquals("Add (6)", "defuri", ns.LookupNamespace("")); AssertEquals("Add (7)", "defuri", ns.DefaultNamespace); AssertEquals("Add (8)", "", ns.LookupPrefix("defuri")); // Try changing some other namespace. ns.AddNamespace("foo", "uri"); AssertEquals("Add (9)", "uri", ns.LookupNamespace("foo")); AssertEquals("Add (10)", "foo", ns.LookupPrefix("uri")); // Make sure that the standard are still set to their // correct values after the modifications above. AssertEquals("Add (11)", "http://www.w3.org/XML/1998/namespace", ns.LookupNamespace("xml")); AssertEquals("Add (12)", "http://www.w3.org/2000/xmlns/", ns.LookupNamespace("xmlns")); AssertEquals("Add (13)", "defuri", ns.LookupNamespace("")); }
/// <include file='doc\XmlSchema.uex' path='docs/doc[@for="XmlSchema.Write5"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void Write(XmlWriter writer, XmlNamespaceManager namespaceManager) { XmlSerializer serializer = new XmlSerializer(typeof(XmlSchema)); XmlSerializerNamespaces ns; if (namespaceManager != null) { ns = new XmlSerializerNamespaces(); bool ignoreXS = false; if (this.Namespaces != null) { //User may have set both nsManager and Namespaces property on the XmlSchema object ignoreXS = this.Namespaces.Namespaces["xs"] != null || this.Namespaces.Namespaces.ContainsValue(XmlReservedNs.NsXs); } if (!ignoreXS && namespaceManager.LookupPrefix(XmlReservedNs.NsXs) == null && namespaceManager.LookupNamespace("xs") == null ) { ns.Add("xs", XmlReservedNs.NsXs); } foreach(string prefix in namespaceManager) { if (prefix != "xml" && prefix != "xmlns") { ns.Add(prefix, namespaceManager.LookupNamespace(prefix)); } } } else if (this.Namespaces != null && this.Namespaces.Count > 0) { Hashtable serializerNS = this.Namespaces.Namespaces; if (serializerNS["xs"] == null && !serializerNS.ContainsValue(XmlReservedNs.NsXs)) { //Prefix xs not defined AND schema namespace not already mapped to a prefix serializerNS.Add("xs", XmlReservedNs.NsXs); } ns = this.Namespaces; } else { ns = new XmlSerializerNamespaces(); ns.Add("xs", XmlSchema.Namespace); if (targetNs != null && targetNs.Length != 0) { ns.Add("tns", targetNs); } } serializer.Serialize(writer, this, ns); }