public void SingleElementWithNamespacePrefixFoundByXPath() { string xml = "<f:root xmlns:f='http://foo.com'>\r\n" + "\t<f:foo></f:foo>\r\n" + "</f:root>"; XmlNamespaceCollection namespaces = new XmlNamespaceCollection(); namespaces.Add(new XmlNamespace("fo", "http://foo.com")); XPathQuery query = new XPathQuery(xml, namespaces); XPathNodeMatch[] nodes = query.FindNodes("//fo:foo"); XPathNodeMatch node = nodes[0]; string nodeValue = "f:foo"; string displayValue = "<f:foo>"; int lineNumber = 1; int linePosition = 2; XPathNodeType nodeType = XPathNodeType.Element; XPathNodeMatch expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType); XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching()); Assert.AreEqual(1, nodes.Length); }
/// <summary> /// Gets the list of namespaces in the namespace list. /// </summary> public XmlNamespaceCollection GetNamespaces() { XmlNamespaceCollection namespaces = new XmlNamespaceCollection(); for (int i = 0; i < namespacesDataGridView.Rows.Count - 1; ++i) { DataGridViewRow row = namespacesDataGridView.Rows[i]; string prefix = GetPrefix(row); string uri = GetNamespace(row); if (prefix.Length == 0 && uri.Length == 0) { // Ignore. } else { namespaces.Add(new XmlNamespace(prefix, uri)); } } return namespaces; }
public void GetRootElementCompletionReturnsRootElementsFromBothFooSchemas() { XmlNamespaceCollection namespaces = new XmlNamespaceCollection(); namespaces.Add(new XmlNamespace(String.Empty, "foo")); XmlCompletionItemCollection items = schemas.GetRootElementCompletion(namespaces); items.Sort(); List <XmlCompletionItem> expectedItems = new List <XmlCompletionItem>(); expectedItems.Add(new XmlCompletionItem("duplicate-foo-note", XmlCompletionItemType.XmlElement)); expectedItems.Add(new XmlCompletionItem("foo-note", XmlCompletionItemType.XmlElement)); Assert.AreEqual(expectedItems.ToArray(), items.ToArray()); }
public void SetUpFixture() { using (XPathQueryControl queryControl = new XPathQueryControl()) { Properties p = new Properties(); expectedNamespaces = new List<XmlNamespace>(); expectedNamespaces.Add(new XmlNamespace("f", "http://foo.com")); expectedNamespaces.Add(new XmlNamespace("s", "http://sharpdevelop.com")); List<string> namespaces = new List<string>(); foreach (XmlNamespace xmlNamespace in expectedNamespaces) { namespaces.Add(xmlNamespace.ToString()); } p.Set("Namespaces", namespaces.ToArray()); queryControl.SetMemento(p); actualNamespaces = queryControl.GetNamespaces(); } }
public void SetUpFixture() { using (XPathQueryControl queryControl = new XPathQueryControl()) { Properties p = new Properties(); expectedNamespaces = new List <XmlNamespace>(); expectedNamespaces.Add(new XmlNamespace("f", "http://foo.com")); expectedNamespaces.Add(new XmlNamespace("s", "http://sharpdevelop.com")); List <string> namespaces = new List <string>(); foreach (XmlNamespace xmlNamespace in expectedNamespaces) { namespaces.Add(xmlNamespace.ToString()); } p.SetList("Namespaces", namespaces); queryControl.SetMemento(p); actualNamespaces = queryControl.GetNamespaces(); } }
public void SetUpFixture() { using (XPathQueryControl queryControl = new XPathQueryControl()) { expectedNamespaces = new List<XmlNamespace>(); expectedNamespaces.Add(new XmlNamespace("w", "http://www.wix.com")); expectedNamespaces.Add(new XmlNamespace("s", "http://sharpdevelop.com")); foreach (XmlNamespace ns in expectedNamespaces) { queryControl.AddNamespace(ns.Prefix, ns.Name); } namespacesAddedToGrid = new List<XmlNamespace>(); for (int i = 0; i < queryControl.NamespacesDataGridView.Rows.Count - 1; ++i) { DataGridViewRow row = queryControl.NamespacesDataGridView.Rows[i]; namespacesAddedToGrid.Add(new XmlNamespace((string)row.Cells[0].Value, (string)row.Cells[1].Value)); } namespaces = queryControl.GetNamespaces(); } }
public void SingleElementWithNamespacePrefixFoundByXPath() { string xml = "<f:root xmlns:f='http://foo.com'>\r\n" + "\t<f:foo></f:foo>\r\n" + "</f:root>"; XmlNamespaceCollection namespaces = new XmlNamespaceCollection(); namespaces.Add(new XmlNamespace("fo", "http://foo.com")); XPathQuery query = new XPathQuery(xml, namespaces); XPathNodeMatch[] nodes = query.FindNodes("//fo:foo"); XPathNodeMatch node = nodes[0]; string nodeValue = "f:foo"; string displayValue = "<f:foo>"; int lineNumber = 1; int linePosition = 2; XPathNodeType nodeType = XPathNodeType.Element; XPathNodeMatch expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType); XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching()); Assert.AreEqual(1, nodes.Length); }
public void SetUpFixture() { using (XPathQueryControl queryControl = new XPathQueryControl()) { expectedNamespaces = new List <XmlNamespace>(); expectedNamespaces.Add(new XmlNamespace("w", "http://www.wix.com")); expectedNamespaces.Add(new XmlNamespace("s", "http://sharpdevelop.com")); foreach (XmlNamespace ns in expectedNamespaces) { queryControl.AddNamespace(ns.Prefix, ns.Name); } namespacesAddedToGrid = new List <XmlNamespace>(); for (int i = 0; i < queryControl.NamespacesDataGridView.Rows.Count - 1; ++i) { DataGridViewRow row = queryControl.NamespacesDataGridView.Rows[i]; namespacesAddedToGrid.Add(new XmlNamespace((string)row.Cells[0].Value, (string)row.Cells[1].Value)); } namespaces = queryControl.GetNamespaces(); } }
public XPathQuery(string xml, XmlNamespaceCollection namespaces) { this.xml = xml; this.namespaces = namespaces; }
public XPathQuery(ITextEditor textEditor, XmlNamespaceCollection namespaces) : this(textEditor.Document.Text, namespaces) { }
/// <summary> /// Gets attribute completion data from a group ref. /// </summary> XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaAttributeGroupRef groupRef, XmlNamespaceCollection namespacesInScope) { XmlSchemaAttributeGroup attributeGroup = FindAttributeGroup(schema, groupRef.RefName.Name); if (attributeGroup != null) { return GetAttributeCompletion(attributeGroup.Attributes, namespacesInScope); } return new XmlCompletionItemCollection(); }
/// <summary> /// Adds an attribute to the completion data collection. /// </summary> /// <remarks> /// Note the special handling of xml:lang attributes. /// </remarks> void AddAttribute(XmlCompletionItemCollection completionItems, XmlSchemaAttribute attribute, XmlNamespaceCollection namespacesInScope) { string name = attribute.Name; if (name == null) { if (attribute.RefName.Namespace == "http://www.w3.org/XML/1998/namespace") { name = String.Concat("xml:", attribute.RefName.Name); } else { string prefix = namespacesInScope.GetPrefix(attribute.RefName.Namespace); if (!String.IsNullOrEmpty(prefix)) { name = String.Concat(prefix, ":", attribute.RefName.Name); } } } if (name != null) { string documentation = GetDocumentation(attribute.Annotation); XmlCompletionItem item = new XmlCompletionItem(name, documentation, XmlCompletionItemType.XmlAttribute); completionItems.Add(item); } }
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaObjectCollection attributes, XmlNamespaceCollection namespacesInScope) { XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection(); foreach (XmlSchemaObject schemaObject in attributes) { XmlSchemaAttribute attribute = schemaObject as XmlSchemaAttribute; XmlSchemaAttributeGroupRef attributeGroupRef = schemaObject as XmlSchemaAttributeGroupRef; if (attribute != null) { if (!IsProhibitedAttribute(attribute)) { AddAttribute(completionItems, attribute, namespacesInScope); } else { prohibitedAttributes.Add(attribute); } } else if (attributeGroupRef != null) { completionItems.AddRange(GetAttributeCompletion(attributeGroupRef, namespacesInScope)); } } return completionItems; }
XmlCompletionItemCollection GetBaseComplexTypeAttributeCompletion(XmlQualifiedName baseTypeName, XmlNamespaceCollection namespacesInScope) { XmlSchemaComplexType baseComplexType = FindNamedType(schema, baseTypeName); if (baseComplexType != null) { return GetAttributeCompletion(baseComplexType, namespacesInScope); } return new XmlCompletionItemCollection(); }
static string LookupPrefix(string namespaceName, XmlNamespaceCollection namespaces) { for (int x = 0; x < namespaces.Count; x++) { if (String.CompareOrdinal(namespaces[x].Namespace, namespaceName) == 0) return namespaces[x].Prefix; } return null; }
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaSimpleContent simpleContent, XmlNamespaceCollection namespacesInScope) { XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection(); XmlSchemaSimpleContentExtension extension = simpleContent.Content as XmlSchemaSimpleContentExtension; if (extension != null) { completionItems.AddRange(GetAttributeCompletion(extension, namespacesInScope)); } return completionItems; }
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaComplexType complexType, XmlNamespaceCollection namespacesInScope) { XmlCompletionItemCollection completionItems = GetAttributeCompletion(complexType.Attributes, namespacesInScope); // Add any complex content attributes. XmlSchemaComplexContent complexContent = complexType.ContentModel as XmlSchemaComplexContent; if (complexContent != null) { XmlSchemaComplexContentExtension extension = complexContent.Content as XmlSchemaComplexContentExtension; XmlSchemaComplexContentRestriction restriction = complexContent.Content as XmlSchemaComplexContentRestriction; if (extension != null) { completionItems.AddRange(GetAttributeCompletion(extension, namespacesInScope)); } else if (restriction != null) { completionItems.AddRange(GetAttributeCompletion(restriction, namespacesInScope)); } } else { XmlSchemaSimpleContent simpleContent = complexType.ContentModel as XmlSchemaSimpleContent; if (simpleContent != null) { completionItems.AddRange(GetAttributeCompletion(simpleContent, namespacesInScope)); } } return completionItems; }
public void Init() { namespaceCollection = new XmlNamespaceCollection(); }
/// <summary> /// Adds project hosting xml namespaces before serialization. /// </summary> public override void Close() { base.Close(); XmlNamespaceCollection.Add("issues", "http://schemas.google.com/projecthosting/issues/2009"); }
public void Init() { namespaceCollection = new XmlNamespaceCollection(); }
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaSimpleContentExtension extension, XmlNamespaceCollection namespacesInScope) { XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection(); completionItems.AddRange(GetAttributeCompletion(extension.Attributes, namespacesInScope)); completionItems.AddRange(GetBaseComplexTypeAttributeCompletion(extension.BaseTypeName, namespacesInScope)); return completionItems; }
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaElement element, XmlNamespaceCollection namespacesInScope) { XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection(); XmlSchemaComplexType complexType = GetElementAsComplexType(element); if (complexType != null) { completionItems.AddRange(GetAttributeCompletion(complexType, namespacesInScope)); } return completionItems; }
public void GetRootElementCompletionReturnsRootElementsFromBothFooSchemas() { XmlNamespaceCollection namespaces = new XmlNamespaceCollection(); namespaces.Add(new XmlNamespace(String.Empty, "foo")); XmlCompletionItemCollection items = schemas.GetRootElementCompletion(namespaces); items.Sort(); List<XmlCompletionItem> expectedItems = new List<XmlCompletionItem>(); expectedItems.Add(new XmlCompletionItem("duplicate-foo-note", XmlCompletionItemType.XmlElement)); expectedItems.Add(new XmlCompletionItem("foo-note", XmlCompletionItemType.XmlElement)); Assert.AreEqual(expectedItems.ToArray(), items.ToArray()); }