public void NotEqualsTest2() { QualifiedName name1 = new QualifiedName("foo", "http://foo.com", "f"); QualifiedName name2 = null; Assert.IsFalse(name1 == name2, "Should not be the same."); }
public void HashCodeTest() { QualifiedName name1 = new QualifiedName("foo", "http://foo.com", "f"); XmlQualifiedName xmlQualifiedName = new XmlQualifiedName("foo", "http://foo.com"); Assert.AreEqual(name1.GetHashCode(), xmlQualifiedName.GetHashCode()); }
public void EqualsTest2() { QualifiedName name1 = new QualifiedName("foo", "http://foo.com", "f"); QualifiedName name2 = new QualifiedName("foo", "http://foo.com", "f"); Assert.AreEqual(name1, name2, "Should be the same."); }
public void EqualsTest3() { QualifiedName name1 = new QualifiedName("foo", "http://foo.com", "f"); QualifiedName name2 = new QualifiedName("foo", "http://foo.com", "ggg"); Assert.IsTrue(name1 == name2, "Should be the same."); }
public void AttributeWithPrefix() { string text = " a:test="; QualifiedName expectedName = new QualifiedName("test", String.Empty, "a"); QualifiedName name = XmlParser.GetQualifiedAttributeName(text, text.Length); Assert.AreEqual(expectedName, name); }
MemberResolveResult ResolveAttribute(XmlReader r, string attributeName) { if (context.ElementPath.Elements.Count == 0) { return(null); } string attributeXmlNamespace; if (attributeName.Contains(":")) { attributeXmlNamespace = r.LookupNamespace(attributeName.Substring(0, attributeName.IndexOf(':'))); attributeName = attributeName.Substring(attributeName.IndexOf(':') + 1); } else { attributeXmlNamespace = r.LookupNamespace(""); } if (attributeName.Contains(".")) { string className = attributeName.Substring(0, attributeName.IndexOf('.')); attributeName = attributeName.Substring(attributeName.IndexOf('.') + 1); return(ResolveProperty(attributeXmlNamespace, className, attributeName, true)); } else { ICSharpCode.XmlEditor.QualifiedName lastElement = context.ElementPath.Elements[context.ElementPath.Elements.Count - 1]; return(ResolveProperty(lastElement.Namespace, lastElement.Name, attributeName, false)); } }
public void SuccessTest8() { string text = "<a type='a"; QualifiedName expectedName = new QualifiedName("type", String.Empty); QualifiedName name = XmlParser.GetQualifiedAttributeNameAtIndex(text, text.Length); Assert.AreEqual(expectedName, name); }
public void AttributeNameWithPrefix2() { string text = "<a xab:test="; QualifiedName expectedName = new QualifiedName("test", String.Empty, "xab"); QualifiedName name = XmlParser.GetQualifiedAttributeNameAtIndex(text, text.IndexOf("xa")); Assert.AreEqual(expectedName, name); }
public void SuccessTest5() { string text = "<a foo="; QualifiedName expectedName = new QualifiedName("foo", String.Empty); QualifiedName name = XmlParser.GetQualifiedAttributeNameAtIndex(text, 3); Assert.AreEqual(expectedName, name); }
public void SuccessTest6() { string text = " foo = '#"; QualifiedName expectedName = new QualifiedName("foo", String.Empty); QualifiedName name = XmlParser.GetQualifiedAttributeName(text, text.Length); Assert.AreEqual(expectedName, name, "Should have retrieved the attribute name 'foo'"); }
public void CreateQualifiedNameCollectionInstanceUsingQualifiedNameCollection() { QualifiedName[] array = new QualifiedName[] { firstName, secondName }; QualifiedNameCollection oldCollection = new QualifiedNameCollection(array); QualifiedNameCollection newCollection = new QualifiedNameCollection(oldCollection); Assert.AreSame(firstName, newCollection[0]); }
public void Init() { firstName = new QualifiedName("first", "first-ns", "first-prefix"); secondName = new QualifiedName("second", "second-ns", "second-prefix"); QualifiedName[] array = new QualifiedName[] { firstName, secondName }; qualifiedNameCollection = new QualifiedNameCollection(array); }
public void Init() { path = new XmlElementPath(); firstQualifiedName = new QualifiedName("foo", "http://foo", "f"); path.AddElement(firstQualifiedName); secondQualifiedName = new QualifiedName("bar", "http://bar", "b"); path.AddElement(secondQualifiedName); }
public void SetUpFixture() { // Get the path for the DesignSurface element. int index = xaml.IndexOf("designer:DesignSurface"); designSurfacePath = XmlParser.GetActiveElementStartPathAtIndex(xaml, index); designSurfacePath2 = XmlParser.GetActiveElementStartPath(xaml, index); // Get the path for the DesignSurface/@Name attribute. index = xaml.IndexOf("Name=\"designSurface\""); designSurfaceNameAttribute = XmlParser.GetQualifiedAttributeNameAtIndex(xaml, index, true); }
public override void FixtureInit() { // Note element path. noteElementPath = new XmlElementPath(); QualifiedName noteQualifiedName = new QualifiedName("note", "http://www.w3schools.com"); noteElementPath.Elements.Add(noteQualifiedName); // Text element path. textElementPath = new XmlElementPath(); textElementPath.Elements.Add(noteQualifiedName); textElementPath.Elements.Add(new QualifiedName("text", "http://www.w3schools.com")); }
public override void FixtureInit() { // Get shipto attributes. shipToPath = new XmlElementPath(); QualifiedName shipOrderName = new QualifiedName("shiporder", "http://www.w3schools.com"); shipToPath.Elements.Add(shipOrderName); shipToPath.Elements.Add(new QualifiedName("shipto", "http://www.w3schools.com")); shipToAttributes = SchemaCompletionData.GetAttributeCompletionData(shipToPath); // Get shiporder attributes. shipOrderPath = new XmlElementPath(); shipOrderPath.Elements.Add(shipOrderName); shipOrderAttributes = SchemaCompletionData.GetAttributeCompletionData(shipOrderPath); }
XmlSchemaObject FindSchemaObjectType(QualifiedName qualifiedName, string elementName, XmlSchemaCompletion schema) { switch (elementName) { case "element": return schema.FindComplexType(qualifiedName); case "attribute": return schema.FindSimpleType(qualifiedName.Name); } return null; }
XmlSchemaCompletion GetSchemaForQualifiedName(QualifiedName name) { XmlSchemaCompletion schema = schemas[name.Namespace]; if (schema != null) { return schema; } return currentSchema; }
XmlSchemaObject FindSchemaObjectReference(QualifiedName qualifiedName, string elementName, XmlSchemaCompletion schema) { switch (elementName) { case "element": return schema.FindRootElement(qualifiedName); case "attribute": return schema.FindAttribute(qualifiedName.Name); case "group": return schema.FindGroup(qualifiedName.Name); case "attributeGroup": return schema.FindAttributeGroup(qualifiedName.Name); } return null; }
/// <summary> /// Gets the parent element path based on the index position. This /// method does not compact the path so it will include all elements /// including those in another namespace in the path. /// </summary> static XmlElementPath GetFullParentElementPath(string xml) { XmlElementPath path = new XmlElementPath(); IDictionary<string, string> namespacesInScope = null; using (StringReader reader = new StringReader(xml)) { using (XmlTextReader xmlReader = new XmlTextReader(reader)) { try { xmlReader.XmlResolver = null; // prevent XmlTextReader from loading external DTDs while (xmlReader.Read()) { switch (xmlReader.NodeType) { case XmlNodeType.Element: if (!xmlReader.IsEmptyElement) { QualifiedName elementName = new QualifiedName(xmlReader.LocalName, xmlReader.NamespaceURI, xmlReader.Prefix); path.AddElement(elementName); } break; case XmlNodeType.EndElement: path.Elements.RemoveLast(); break; } } } catch (XmlException) { namespacesInScope = xmlReader.GetNamespacesInScope(XmlNamespaceScope.All); } } } // Add namespaces in scope for the last element read. if (namespacesInScope != null) { foreach (KeyValuePair<string, string> ns in namespacesInScope) { path.NamespacesInScope.Add(new XmlNamespace(ns.Key, ns.Value)); } } return path; }
public void DesignSurfaceNameAttribute() { QualifiedName expectedName = new QualifiedName("Name", "clr-namespace:ICSharpCode.WpfDesign.Designer;assembly=ICSharpCode.WpfDesign.Designer", String.Empty); Assert.AreEqual(expectedName, designSurfaceNameAttribute); }
/// <summary> /// Finds the element in the collection of schema objects. /// </summary> XmlSchemaElement FindElement(XmlSchemaObjectCollection items, QualifiedName name) { foreach (XmlSchemaObject schemaObject in items) { XmlSchemaElement element = schemaObject as XmlSchemaElement; XmlSchemaSequence sequence = schemaObject as XmlSchemaSequence; XmlSchemaChoice choice = schemaObject as XmlSchemaChoice; XmlSchemaGroupRef groupRef = schemaObject as XmlSchemaGroupRef; XmlSchemaElement matchedElement = null; if (element != null) { if (element.Name != null) { if (name.Name == element.Name) { return element; } } else if (element.RefName != null) { if (name.Name == element.RefName.Name) { matchedElement = FindElement(element.RefName); } else { // Abstract element? XmlSchemaElement abstractElement = FindElement(element.RefName); if (abstractElement != null && abstractElement.IsAbstract) { matchedElement = FindSubstitutionGroupElement(abstractElement.QualifiedName, name); } } } } else if (sequence != null) { matchedElement = FindElement(sequence.Items, name); } else if (choice != null) { matchedElement = FindElement(choice.Items, name); } else if (groupRef != null) { matchedElement = FindElement(groupRef, name); } // Did we find a match? if (matchedElement != null) { return matchedElement; } } return null; }
/// <summary> /// Finds the named child element contained in the extension element. /// </summary> XmlSchemaElement FindChildElement(XmlSchemaComplexContentExtension extension, QualifiedName name) { XmlSchemaComplexType complexType = FindNamedType(schema, extension.BaseTypeName); if (complexType != null) { XmlSchemaElement matchedElement = FindChildElement(complexType, name); if (matchedElement == null) { XmlSchemaSequence sequence = extension.Particle as XmlSchemaSequence; XmlSchemaChoice choice = extension.Particle as XmlSchemaChoice; XmlSchemaGroupRef groupRef = extension.Particle as XmlSchemaGroupRef; if (sequence != null) { return FindElement(sequence.Items, name); } else if (choice != null) { return FindElement(choice.Items, name); } else if (groupRef != null) { return FindElement(groupRef, name); } } else { return matchedElement; } } return null; }
/// <summary> /// Finds the named child element contained in the restriction element. /// </summary> XmlSchemaElement FindChildElement(XmlSchemaComplexContentRestriction restriction, QualifiedName name) { XmlSchemaSequence sequence = restriction.Particle as XmlSchemaSequence; XmlSchemaGroupRef groupRef = restriction.Particle as XmlSchemaGroupRef; if (sequence != null) { return FindElement(sequence.Items, name); } else if (groupRef != null) { return FindElement(groupRef, name); } return null; }
XmlSchemaElement FindChildElement(XmlSchemaComplexType complexType, QualifiedName name) { XmlSchemaSequence sequence = complexType.Particle as XmlSchemaSequence; XmlSchemaChoice choice = complexType.Particle as XmlSchemaChoice; XmlSchemaGroupRef groupRef = complexType.Particle as XmlSchemaGroupRef; XmlSchemaAll all = complexType.Particle as XmlSchemaAll; XmlSchemaComplexContent complexContent = complexType.ContentModel as XmlSchemaComplexContent; if (sequence != null) { return FindElement(sequence.Items, name); } else if (choice != null) { return FindElement(choice.Items, name); } else if (complexContent != null) { XmlSchemaComplexContentExtension extension = complexContent.Content as XmlSchemaComplexContentExtension; XmlSchemaComplexContentRestriction restriction = complexContent.Content as XmlSchemaComplexContentRestriction; if (extension != null) { return FindChildElement(extension, name); } else if (restriction != null) { return FindChildElement(restriction, name); } } else if (groupRef != null) { return FindElement(groupRef, name); } else if (all != null) { return FindElement(all.Items, name); } return null; }
/// <summary> /// Finds an element that matches the specified <paramref name="name"/> /// from the children of the given <paramref name="element"/>. /// </summary> XmlSchemaElement FindChildElement(XmlSchemaElement element, QualifiedName name) { XmlSchemaComplexType complexType = GetElementAsComplexType(element); if (complexType != null) { return FindChildElement(complexType, name); } return null; }
/// <summary> /// Finds the complex type with the specified name. /// </summary> public XmlSchemaComplexType FindComplexType(QualifiedName name) { XmlQualifiedName qualifiedName = new XmlQualifiedName(name.Name, name.Namespace); return FindNamedType(schema, qualifiedName); }
public void AddElement(QualifiedName elementName) { elements.Add(elementName); }
XmlSchemaElement FindElement(XmlSchemaGroupRef groupRef, QualifiedName name) { XmlSchemaGroup schemaGroup = FindGroup(groupRef.RefName.Name); if (schemaGroup != null) { XmlSchemaSequence sequence = schemaGroup.Particle as XmlSchemaSequence; XmlSchemaChoice choice = schemaGroup.Particle as XmlSchemaChoice; if(sequence != null) { return FindElement(sequence.Items, name); } else if (choice != null) { return FindElement(choice.Items, name); } } return null; }
/// <summary> /// Finds an element in the schema. /// </summary> /// <remarks> /// Only looks at the elements that are defined in the /// root of the schema so it will not find any elements /// that are defined inside any complex types. /// </remarks> public XmlSchemaElement FindRootElement(QualifiedName name) { foreach (XmlSchemaElement element in schema.Elements.Values) { if (name.Equals(element.QualifiedName)) { return element; } } return null; }
/// <summary> /// Looks for the substitution group element of the specified name. /// </summary> XmlSchemaElement FindSubstitutionGroupElement(XmlQualifiedName groupName, QualifiedName name) { foreach (XmlSchemaElement element in schema.Elements.Values) { if (element.SubstitutionGroup == groupName) { if (element.Name != null) { if (element.Name == name.Name) { return element; } } } } return null; }