public static void AssertIsChildElementOf(XmlElement parentElement,XmlElement expectedChildElement,string queryChildElementPath,XmlNamespaceManager namespaceManager) { XPathNavigator parentElementNavigator=parentElement.CreateNavigator(); XPathNavigator foundChildElementNavigator=parentElementNavigator.SelectSingleNode(queryChildElementPath,namespaceManager); Assert.IsNotNull(foundChildElementNavigator); XmlElement foundChildElement=(XmlElement)foundChildElementNavigator.UnderlyingObject; Assert.AreSame(expectedChildElement,foundChildElement); }
public static void AssertChildElementsCount(XmlElement parentElement, int expectedChildNodesCount) { XPathNavigator parentElementNavigator=parentElement.CreateNavigator(); XPathNodeIterator childNodesSet=parentElementNavigator.SelectChildren(XPathNodeType.All) ; int childNodesCount=childNodesSet.Count; Assert.IsTrue(expectedChildNodesCount==childNodesCount); }
public static void AssertIsUmlAttributeOf(XmlElement relevantElement,string localAttributeName,XmlNamespaceManager namespaceManager) { XPathNavigator relevantElementNavigator=relevantElement.CreateNavigator(); string query=ATTRIBUTE_SELECTION_QUERY_START+localAttributeName; XPathNavigator foundAttributeNavigator=relevantElementNavigator.SelectSingleNode(query,namespaceManager); Assert.IsNotNull(foundAttributeNavigator); XmlAttribute foundAttribute=(XmlAttribute)foundAttributeNavigator.UnderlyingObject; Assert.IsNotNull(foundAttribute); }
private static byte[] CalculateC14nByteRange(XmlElement element, XmlDocument doc) { XmlElement cloneElement = (XmlElement)element.CloneNode(true); NormalizeNamespaces(element.CreateNavigator(), cloneElement.CreateNavigator()); XmlDocument elememntDoc = new XmlDocument(doc.NameTable); elememntDoc.LoadXml(cloneElement.OuterXml); XmlDsigC14NTransform c14nTransform = new XmlDsigC14NTransform(); c14nTransform.LoadInput(elememntDoc); return ((MemoryStream)c14nTransform.GetOutput()).ToArray(); }
/// <summary> /// Initializes this instance. /// </summary> /// <remarks>Documented by Dev03, 2007-08-06</remarks> private void Initialize(bool ignoreOldVersion) { m_generalSettings = (XmlElement)m_dictionary.SelectSingleNode(m_xpathGenSet); m_userSettings = (XmlElement)m_dictionary.SelectSingleNode(m_xpathUsrSet); m_queryOptions = new MLifter.DAL.XML.XmlQueryOptions(this, parent); settings = new XmlSettings(this, Parent.GetChildParentClass(this)); allowed_settings = new XmlAllowedSettings(this, Parent.GetChildParentClass(this)); //check dictionary version if (this.Version > m_CurrentVersion) { CloseStream(); throw new DictionaryFormatNotSupported(this.Version); } else if (this.Version < m_CurrentVersion && !ignoreOldVersion) { CloseStream(); throw new DictionaryFormatOldVersion(this.Version); } XPathNavigator navigator; XPathExpression expression; XPathNodeIterator nodeIterator; //read commentsound m_audioComments = new List<string>(); navigator = m_generalSettings.CreateNavigator(); expression = navigator.Compile(m_xpathCommentSound); expression.AddSort(m_xpathAttributeId, XmlSortOrder.Ascending, XmlCaseOrder.None, String.Empty, XmlDataType.Number); nodeIterator = navigator.Select(expression); while (nodeIterator.MoveNext()) m_audioComments.Add(nodeIterator.Current.Value); //read boxsize m_Boxes = new XmlBoxes(this, Parent.GetChildParentClass(this)); navigator = m_userSettings.CreateNavigator(); expression = navigator.Compile(m_xpathBoxsize); expression.AddSort(m_xpathAttributeId, XmlSortOrder.Ascending, XmlCaseOrder.None, String.Empty, XmlDataType.Number); nodeIterator = navigator.Select(expression); while (nodeIterator.MoveNext()) { string boxSizeValue = nodeIterator.Current.Value; int currentId = 0; if (nodeIterator.Current.MoveToAttribute(m_xpathId, String.Empty)) { if (Int32.TryParse(nodeIterator.Current.Value, out currentId)) { if ((currentId > 0) && (currentId < m_numberOfBoxes)) // box 1 to 9 (pool and box 10 are not written) { m_Boxes.Box[currentId].MaximalSize = XmlConvert.ToInt32(boxSizeValue); } } } } //read querychapter m_queryChapters = new List<int>(); navigator = m_userSettings.CreateNavigator(); expression = navigator.Compile(m_xpathQueryChapter); expression.AddSort(m_xpathAttributeId, XmlSortOrder.Ascending, XmlCaseOrder.None, String.Empty, XmlDataType.Number); nodeIterator = navigator.Select(expression); while (nodeIterator.MoveNext()) m_queryChapters.Add(XmlConvert.ToInt32(nodeIterator.Current.Value)); m_cards = new MLifter.DAL.XML.XmlCards(this, parent.GetChildParentClass(this)); m_chapters = new MLifter.DAL.XML.XmlChapters(this, Parent.GetChildParentClass(this)); m_statistics = new MLifter.DAL.XML.XmlStatistics(this); m_AllowedQueryTypes = new XML.XmlAllowedQueryTypes(this, Parent.GetChildParentClass(this)); m_AllowedQueryDirections = new XML.XmlAllowedQueryDirections(this, Parent.GetChildParentClass(this)); this.Category.IdChanged += new EventHandler(Category_IdChanged); }
internal XmlSettings(XmlDictionary dictionary, ParentClass parent) { this.parent = parent; this.dictionary = dictionary; m_dictionary = dictionary.Dictionary; m_Settings = (XmlElement)m_dictionary.SelectSingleNode(m_basePath); m_MultipleChoiceOptions = new XmlQueryMultipleChoiceOptions(dictionary, Parent.GetChildParentClass(this)); m_generalSettings = (XmlElement)m_dictionary.SelectSingleNode(m_xpathGenSet); m_userSettings = (XmlElement)m_dictionary.SelectSingleNode(m_xpathUsrSet); XPathNavigator navigator; XPathExpression expression; XPathNodeIterator nodeIterator; //read commentsound m_audioComments = new List<string>(); navigator = m_generalSettings.CreateNavigator(); expression = navigator.Compile(m_xpathCommentSound); expression.AddSort(m_xpathAttributeId, XmlSortOrder.Ascending, XmlCaseOrder.None, String.Empty, XmlDataType.Number); nodeIterator = navigator.Select(expression); while (nodeIterator.MoveNext()) m_audioComments.Add(nodeIterator.Current.Value); }
public XElement ConvertToXElement(XmlElement xmlElement) { return XElement.Load((xmlElement.CreateNavigator().ReadSubtree())); }
public OpenIdRpxAuthInfo(XmlElement authElement) { auth = authElement; xpathNavigator = auth.CreateNavigator(); }
/// <summary> /// Gets a <see cref="FrameworkTemplate"/> based on the specified parameters. /// </summary> /// <param name="xmlElement">The xml element to get template xaml from.</param> /// <param name="parentObject">The <see cref="XamlObject"/> to use as source for resources and contextual information.</param> /// <returns>A <see cref="FrameworkTemplate"/> based on the specified parameters.</returns> public static FrameworkTemplate GetFrameworkTemplate(XmlElement xmlElement, XamlObject parentObject) { var nav = xmlElement.CreateNavigator(); var ns = new Dictionary<string, string>(); while (true) { var nsInScope = nav.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml); foreach (var ak in nsInScope) { if (!ns.ContainsKey(ak.Key) && ak.Key != "") ns.Add(ak.Key, ak.Value); } if (!nav.MoveToParent()) break; } xmlElement = (XmlElement)xmlElement.CloneNode(true); foreach (var dictentry in ns.ToList()) { var value = dictentry.Value; if (value.StartsWith("clr-namespace") && !value.Contains(";assembly=")) { if (!string.IsNullOrEmpty(parentObject.OwnerDocument.CurrentProjectAssemblyName)) { value += ";assembly=" + parentObject.OwnerDocument.CurrentProjectAssemblyName; } } xmlElement.SetAttribute("xmlns:" + dictentry.Key, value); } var keyAttrib = xmlElement.GetAttribute("Key", XamlConstants.XamlNamespace); if (string.IsNullOrEmpty(keyAttrib)) { xmlElement.SetAttribute("Key", XamlConstants.XamlNamespace, "$$temp&&§§%%__"); } var xaml = xmlElement.OuterXml; xaml = "<ResourceDictionary xmlns=\"http://schemas.microsoft.com/netfx/2007/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">" + xaml + "</ResourceDictionary>"; StringReader stringReader = new StringReader(xaml); XmlReader xmlReader = XmlReader.Create(stringReader); var xamlReader = new XamlXmlReader(xmlReader, parentObject.ServiceProvider.SchemaContext); var seti = new XamlObjectWriterSettings(); var resourceDictionary = new ResourceDictionary(); var obj = parentObject; while (obj != null) { if (obj.Instance is ResourceDictionary) { var r = obj.Instance as ResourceDictionary; foreach (var k in r.Keys) { if (!resourceDictionary.Contains(k)) resourceDictionary.Add(k, r[k]); } } else if (obj.Instance is FrameworkElement) { var r = ((FrameworkElement)obj.Instance).Resources; foreach (var k in r.Keys) { if (!resourceDictionary.Contains(k)) resourceDictionary.Add(k, r[k]); } } obj = obj.ParentObject; } seti.BeforePropertiesHandler = (s, e) => { if (seti.BeforePropertiesHandler != null) { var rr = e.Instance as ResourceDictionary; rr.MergedDictionaries.Add(resourceDictionary); seti.BeforePropertiesHandler = null; } }; var writer = new XamlObjectWriter(parentObject.ServiceProvider.SchemaContext, seti); XamlServices.Transform(xamlReader, writer); var result = (ResourceDictionary)writer.Result; var enr = result.Keys.GetEnumerator(); enr.MoveNext(); var rdKey = enr.Current; var template = result[rdKey] as FrameworkTemplate; result.Remove(rdKey); return template; }
public static void InsertNamespacesIntoElement(Hashtable namespacesHash, XmlElement node) { XPathNavigator nav = node.CreateNavigator(); if (string.IsNullOrEmpty(nav.Prefix) && string.IsNullOrEmpty(nav.GetAttribute("xmlns", ""))) { nav.CreateAttribute("", "xmlns", "", nav.NamespaceURI); } foreach (DictionaryEntry namespacePair in namespacesHash) { string[] attrName = ((string)namespacePair.Key).Split(':'); if (attrName.Length > 1 && !node.HasAttribute(attrName[0] + ":" + attrName[1])) { nav.CreateAttribute(attrName[0], attrName[1], "", (string)namespacePair.Value); } } }
internal Style GetStyle(IGraphics gr, Style parentStyle, XmlElement e, ElementType et) { Style ret=parentStyle == null ? blockStyle : parentStyle; bool foundMatch=false; foreach ( Style s in Styles ) { if ( s.IsMatch(e.CreateNavigator(), nsMgr) ) { ret=Cascade(gr, ret, s); foundMatch=true; } } bool emptyModel=et != null && et.ContentType == ElementContentType.Empty; if ( !foundMatch ) { // TODO: M: could optimise this perhaps XmlElement parent=e.ParentNode as XmlElement; if ( parent == null ) ret=Cascade(gr, ret, new BlockStyle()); else if ( HasText(parent) || emptyModel ) ret=Cascade(gr, ret, new InlineStyle()); else ret=Cascade(gr, ret, new BlockStyle()); } if ( e.HasChildNodes ) // if element has child nodes, it cannot be shown as empty ret.Empty=false; else if ( emptyModel ) // empty element in DTD so flag as such ret.Empty=true; return ret; }
public Type GetStyleType(XmlElement e) { foreach ( Style s in Styles ) { if ( s.IsMatch(e.CreateNavigator(), nsMgr) ) return s.GetType(); } // TODO: L: this is wrong according to GetStyle (won't always match) // but this is currently only used to find table classes, so doesn't matter return null; }
public static void AssertIsXmiAttributeOf(XmlElement ownerElement, string localAttributeName,string namespaceURI) { XPathNavigator ownerElementNavigator=ownerElement.CreateNavigator(); bool foundAttribute=ownerElementNavigator.MoveToAttribute(localAttributeName,namespaceURI); Assert.IsTrue(foundAttribute); }
public static void AssertIsCorrectXmiAttributeValue(XmlElement ownerElement,string localAttributeName,string namespaceURI,string expectedAttributeValue) { XPathNavigator ownerElementNavigator=ownerElement.CreateNavigator(); string foundAttributeValue=ownerElementNavigator.GetAttribute(localAttributeName,namespaceURI); Assert.AreEqual(expectedAttributeValue,foundAttributeValue); }
/// <summary> /// Used to find matching style rules in the cascading order /// </summary> /// <param name="elt">The element to find styles for</param> /// <param name="pseudoElt">The pseudo-element to find styles for</param> /// <param name="ml">The medialist that the document is using</param> /// <param name="csd">A CssStyleDeclaration that holds the collected styles</param> protected internal override void GetStylesForElement(XmlElement elt, string pseudoElt, MediaList ml, CssCollectedStyleDeclaration csd) { XPathNavigator nav = elt.CreateNavigator(); foreach(CssXPathSelector sel in XPathSelectors) { // TODO: deal with pseudoElt if(sel != null && sel.Matches(nav)) { ((CssStyleDeclaration)Style).GetStylesForElement(csd, sel.Specificity); break; } } }