private bool CompareAsNumber(XPathReader reader) { double n1, n2; var operand_var1 = _Operand1.GetValue(reader); var operand_var2 = _Operand2.GetValue(reader); try { n1 = Convert.ToDouble(operand_var1); n2 = Convert.ToDouble(operand_var2); } catch (Exception) { return(false); } return(_Operator switch { Operator.Op.Lt when n1 <n2 => true, Operator.Op.Gt when n1> n2 => true, Operator.Op.Le when n1 <= n2 => true, Operator.Op.Ge when n1 >= n2 => true, Operator.Op.Eq when n1.Equals(n2) => true, Operator.Op.Ne when !n1.Equals(n2) => true, _ => false });
// // predicate could be result in two results type // 1). Number: position query // 2). Boolean // internal override bool MatchNode(XPathReader reader) { if (!_Axis.MatchNode(reader)) { return(false); } var ret = false; if (reader.NodeType != XmlNodeType.EndElement && reader.ReadMethod != ReadMethods.MoveToElement) { ++_MatchCount; // // send position information down to the predicates // _Predicate.PositionCount = _MatchCount; } var obj = _Predicate.GetValue(reader); if (obj is bool && Convert.ToBoolean(obj)) { ret = true; } else if (obj is double && Convert.ToDouble(obj).Equals(_MatchCount)) { ret = true; //we need to know how many this axis has been evaluated } else if (obj != null && !(obj is double || obj is bool)) { ret = true; //object is node set } return(ret); }
// // boolean lang(string) // private bool Lang(XPathReader reader) { var str = _Qy.GetValue(reader).ToString(); var lang = reader.XmlLang.ToLower(); return(lang.Equals(str) || str.Equals(lang.Split('-')[0])); }
public XPathStream(XmlReader reader, Encoding encoding, SchemaMetaData schemaMetaData,IBaseMessageContext context) { m_context = context; m_schemaMetaData = schemaMetaData; xPathCollection = new XPathCollection(); foreach (var item in m_schemaMetaData.Properties) { xPathCollection.Add(item.Key); } m_bodyPath = new LinkedList<string>(); m_outputStream = new MemoryStream(); this.m_reader = new XPathReader(reader, xPathCollection); this.m_writer = XmlWriter.Create(this.m_outputStream); }
// // boolean boolean(object) // Number: NaN, 0 -> false // String: Length = 0 -> false // Node-set: empty -> false // // <Root><e a='1'>text</e></Root> // 1). /Root/e[boolean(2)] // 2). /Root/e[boolean[string(child::text)] // 3). /Root/e[boolean(child::text)] internal bool ToBoolean(XPathReader reader) { var ret = true; var obj = _Qy.GetValue(reader); if (obj is double) { var number = Convert.ToDouble(obj); if (number.Equals(0d) || double.IsNaN(number)) { ret = false; } } else if (obj is string) { if (obj.ToString().Length == 0) { ret = false; } } else if (obj is bool) { ret = Convert.ToBoolean(obj); } else if (obj is null && reader.NodeType != XmlNodeType.EndElement) { ret = false; } return(ret); } // toBoolean
/// <summary> /// Get a node name or namespace based on an XPATH query run against the body stream /// </summary> /// <param name="_XPathResultType"></param> /// <param name="_XPathQuery"></param> /// <returns></returns> private void SetMessageTypeVariables() { string _XPathQuery = "/*"; try { XmlTextReader xmlTextReader = new XmlTextReader(documentStream); XPathCollection xPathCollection = new XPathCollection(); xPathCollection.Add(_XPathQuery); XPathReader xPathReader = new XPathReader(xmlTextReader, xPathCollection); while (xPathReader.ReadUntilMatch()) { if (xPathReader.Match(_XPathQuery)) { rootNodeName = xPathReader.LocalName; rootNodeNamespace = xPathReader.NamespaceURI; messageTypePropertiesSet = true; } } } catch { //Don't rethrow the exception, if it's a flat file set message type properties to blank values rootNodeName = ""; rootNodeNamespace = ""; messageTypePropertiesSet = true; } documentStream.Position = 0; }
public void Execute(ref IBaseMessage inmsg, IPipelineContext pc) { string _XPathQuery = "/*"; string rootNodeName = string.Empty; string rootNodeNamespace = string.Empty; XmlTextReader xmlTextReader = new XmlTextReader(inmsg.BodyPart.GetOriginalDataStream()); XPathCollection xPathCollection = new XPathCollection(); xPathCollection.Add(_XPathQuery); XPathReader xPathReader = new XPathReader(xmlTextReader, xPathCollection); while (xPathReader.ReadUntilMatch()) { if (xPathReader.Match(_XPathQuery)) { rootNodeName = xPathReader.LocalName; rootNodeNamespace = xPathReader.NamespaceURI; } } inmsg.Context.Promote(BizTalkGlobalPropertySchemaEnum.MessageType.ToString(), ContextPropertyNamespaces._BTSPropertyNamespace, string.Format("{0}#{1}", rootNodeNamespace, rootNodeName)); inmsg.BodyPart.Data.Position = 0; }
public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg) { string errorMessage; if (!Validate(out errorMessage)) { throw new ArgumentException(errorMessage); } String value = null; IBaseMessagePart bodyPart = pInMsg.BodyPart; Stream inboundStream = bodyPart.GetOriginalDataStream(); VirtualStream virtualStream = new VirtualStream(VirtualStream.MemoryFlag.AutoOverFlowToDisk); ReadOnlySeekableStream readOnlySeekableStream = new ReadOnlySeekableStream(inboundStream, virtualStream); XmlTextReader xmlTextReader = new XmlTextReader(readOnlySeekableStream); XPathCollection xPathCollection = new XPathCollection(); XPathReader xPathReader = new XPathReader(xmlTextReader, xPathCollection); xPathCollection.Add(XPath); while (xPathReader.ReadUntilMatch()) { if (xPathReader.Match(0)) { if (xPathReader.NodeType == XmlNodeType.Attribute) { value = xPathReader.GetAttribute(xPathReader.Name); } else { value = xPathReader.ReadString(); } if (PromoteProperty) { pInMsg.Context.Promote(new ContextProperty(PropertyPath), value); } else { pInMsg.Context.Write(new ContextProperty(PropertyPath), value); } break; } } if (string.IsNullOrEmpty(value) && ThrowIfNoMatch) { throw new InvalidOperationException("The specified XPath did not exist or contained an empty value."); } readOnlySeekableStream.Position = 0; pContext.ResourceTracker.AddResource(readOnlySeekableStream); bodyPart.Data = readOnlySeekableStream; return(pInMsg); }
public void Disassemble(IPipelineContext pContext, IBaseMessage pInMsg) { string errorMessage; if (!Validate(out errorMessage)) { throw new ArgumentException(errorMessage); } var data = pInMsg.BodyPart.GetOriginalDataStream(); const int bufferSize = 0x280; const int thresholdSize = 0x100000; if (!data.CanSeek || !data.CanRead) { data = new ReadOnlySeekableStream(data, new VirtualStream(bufferSize, thresholdSize), bufferSize); pContext.ResourceTracker.AddResource(data); } XmlTextReader xmlTextReader = new XmlTextReader(data); XPathCollection xPathCollection = new XPathCollection(); XPathReader xPathReader = new XPathReader(xmlTextReader, xPathCollection); xPathCollection.Add(Xpath); var ms = new MemoryStream(); int readBytes = 0; bool found = false; while (xPathReader.ReadUntilMatch()) { if (xPathReader.Match(0)) { var bw = new BinaryWriter(ms); byte[] buffer = new byte[bufferSize]; while ((readBytes = xPathReader.BaseReader.ReadElementContentAsBase64(buffer, 0, bufferSize)) > 0) { bw.Write(buffer); } bw.Flush(); found = true; break; } } if (!found) { throw new ArgumentException("Could not element at specified xpath"); } ms.Seek(0, SeekOrigin.Begin); ms.Position = 0; var docType = Microsoft.BizTalk.Streaming.Utils.GetDocType(new MarkableForwardOnlyEventingReadStream(ms)); pInMsg.Context.Promote(new ContextProperty(SystemProperties.MessageType), docType); pInMsg.BodyPart.Data = ms; _outputQueue.Enqueue(pInMsg); }
// // <e><e1>1</e1><e2>2</e2></e> // // e[ e1 | e2 = 1] // // results: // e // // Union query needs to return two objects // // The only success situation is the two attribute situations // because only the attribute within current scope are cached. // internal override object GetValue(XPathReader reader) { var lv_ObjArray = new object[2]; lv_ObjArray[0] = _Query1.GetValue(reader); lv_ObjArray[1] = _Query2.GetValue(reader); return(lv_ObjArray); }
protected override object ExecuteQueryAsValue(Query query) { throw new NotImplementedException(); bool parseXsd = Provider.SchemaUrl == null; string xpath = string.Empty; XPathReader reader = new XPathReader(Provider.Url, xpath); }
internal override object GetValue(XPathReader reader) { if (reader.HasValue) { return(reader.Value); } throw new XPathReaderException("Can't get the element value"); }
public IEnumerable <object> ReadData(string fileName, string xPath, int maxRowsToRead) { string rowGrouper = ""; XPathReader xpr = new XPathReader(fileName, xPath); while (xpr.ReadUntilMatch()) { string xml = xpr.ReadOuterXml(); Debug.WriteLine(xml); } using (XmlReader xmlReader = XmlReader.Create(fileName, new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore })) { foreach (var path in XpathParts(xPath)) { if (!xmlReader.SkipToElement(path)) { throw new InvalidOperationException("XML element " + path + " was not found."); } } DataSet dataSet = new DataSet(); int readedRows = 0; while (xmlReader.Read()) { if (xmlReader.Name.Equals(rowGrouper) && (xmlReader.NodeType == XmlNodeType.Element)) { var rowElement = (XElement)XNode.ReadFrom(xmlReader); string xml = rowElement.ToStringOrEmpty(); if (readedRows == 0) { dataSet = new DataSet(); } dataSet = this.formatter.Format(xml, dataSet) as DataSet; readedRows++; if (maxRowsToRead <= 0 || (maxRowsToRead > 0 && readedRows >= maxRowsToRead)) { readedRows = 0; yield return(dataSet); } } } if (readedRows > 0) { yield return(dataSet); } } }
public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg) { String value = null; bool suspend = false; IBaseMessagePart bodyPart = pInMsg.BodyPart; Stream inboundStream = bodyPart.GetOriginalDataStream(); VirtualStream virtualStream = new VirtualStream(VirtualStream.MemoryFlag.AutoOverFlowToDisk); ReadOnlySeekableStream readOnlySeekableStream = new ReadOnlySeekableStream(inboundStream, virtualStream); XmlTextReader xmlTextReader = new XmlTextReader(readOnlySeekableStream); XPathCollection xPathCollection = new XPathCollection(); XPathReader xPathReader = new XPathReader(xmlTextReader, xPathCollection); xPathCollection.Add(XPath); while (xPathReader.ReadUntilMatch()) { if (xPathReader.Match(0)) { if (xPathReader.NodeType == XmlNodeType.Attribute) { value = xPathReader.GetAttribute(xPathReader.Name); } else { value = xPathReader.ReadString(); } break; } } suspend = ScriptExpressionHelper.ValidateExpression(value, Expression); if (suspend) { readOnlySeekableStream.Position = 0; pContext.ResourceTracker.AddResource(readOnlySeekableStream); bodyPart.Data = readOnlySeekableStream; pInMsg.Context.Write("SuspendAsNonResumable", "http://schemas.microsoft.com/BizTalk/2003/system-properties", true); pInMsg.Context.Write("SuppressRoutingFailureDiagnosticInfo", "http://schemas.microsoft.com/BizTalk/2003/system-properties", true); throw new Exception(String.Format("Expression {0} {1} did not evaluate to true", value, Expression)); } else { pInMsg = null; } return(pInMsg); }
public void Execute(ref IBaseMessage inmsg, IPipelineContext pc) { XmlTextReader xmlTextReader = new XmlTextReader(inmsg.BodyPart.GetOriginalDataStream()); XPathCollection xPathCollection = GetXPathCollection(); XPathReader xPathReader = new XPathReader(xmlTextReader, xPathCollection); while (xPathReader.ReadUntilMatch()) { for (int i = 0; i < xPathCollection.Count; i++) { if (xPathReader.Match(i)) { string value = null; _XPathInstructions.ElementAt(i).IsFound = true; switch (_XPathInstructions.ElementAt(i).XPathResultType) { case XPathResultTypeEnum.Name: value = xPathReader.LocalName; break; case XPathResultTypeEnum.Namespace: value = xPathReader.NamespaceURI; break; case XPathResultTypeEnum.Value: value = xPathReader.ReadString(); break; } if (_XPathInstructions.ElementAt(i).Promotion == ContextInstructionTypeEnum.Promote) { inmsg.Context.Promote(_XPathInstructions.ElementAt(i).PropertyName, _XPathInstructions.ElementAt(i).PropertyNamespace, TypeCaster.GetTypedObject(value, _XPathInstructions.ElementAt(i).Type)); } else { inmsg.Context.Write(_XPathInstructions.ElementAt(i).PropertyName, _XPathInstructions.ElementAt(i).PropertyNamespace, TypeCaster.GetTypedObject(value, _XPathInstructions.ElementAt(i).Type)); } } } } for (int i = 0; i < xPathCollection.Count; i++) { if (_XPathInstructions.ElementAt(i).IsFound == false && _XPathInstructions.ElementAt(i).ExceptionIfNotFound == true) { throw new Exception("Unable to evaluate XPath expression " + _XPathInstructions.ElementAt(i).XPathQuery + " against the message."); } } inmsg.BodyPart.Data.Position = 0; }
public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg) { string errorMessage; if (!Validate(out errorMessage)) { throw new ArgumentException(errorMessage); } String value = null; IBaseMessagePart bodyPart = pInMsg.BodyPart; Stream inboundStream = bodyPart.GetOriginalDataStream(); VirtualStream virtualStream = new VirtualStream(VirtualStream.MemoryFlag.AutoOverFlowToDisk); ReadOnlySeekableStream readOnlySeekableStream = new ReadOnlySeekableStream(inboundStream, virtualStream); XmlTextReader xmlTextReader = new XmlTextReader(readOnlySeekableStream); XPathCollection xPathCollection = new XPathCollection(); XPathReader xPathReader = new XPathReader(xmlTextReader, xPathCollection); xPathCollection.Add(XPath); while (xPathReader.ReadUntilMatch()) { if (xPathReader.Match(0)) { value = xPathReader.ReadString(); if (PromoteProperty) { pInMsg.Context.Promote(new ContextProperty(PropertyPath), value); } else { pInMsg.Context.Write(new ContextProperty(PropertyPath), value); } break; } } if (string.IsNullOrEmpty(value) && ThrowIfNoMatch) { throw new InvalidOperationException("The specified XPath did not exist or contained an empty value."); } readOnlySeekableStream.Position = 0; pContext.ResourceTracker.AddResource(readOnlySeekableStream); bodyPart.Data = readOnlySeekableStream; return pInMsg; }
internal override object GetValue(XPathReader reader) { var ret = _Operand1.GetValue(reader); if (!Convert.ToBoolean(ret)) { ret = _Operand2.GetValue(reader); } #if DEBUG1 Console.WriteLine("OrExpr: {0}", ret); #endif return(ret); }
internal override object GetValue(XPathReader reader) { var obj = _FuncType switch { Function.FunctionType.FuncBoolean => ToBoolean(reader), Function.FunctionType.FuncNot => Not(reader), Function.FunctionType.FuncTrue => true, Function.FunctionType.FuncFalse => false, Function.FunctionType.FuncLang => Lang(reader), _ => new object() }; return(obj); }
// The reader will be the current element node // We need to restore the internal override object GetValue(XPathReader reader) { var lv_BaseReader = reader.BaseReader; object ret = null; if (lv_BaseReader.MoveToAttribute(Name)) { ret = reader.Value; } //Move back to the parent lv_BaseReader.MoveToElement(); return(ret); }
// try to match the node internal override bool MatchNode(XPathReader reader) { if (NodeType == XPathNodeType.All) { return(true); } if (!MatchType(NodeType, reader.NodeType)) { return(false); } if (Name != string.Empty && (Name != reader.LocalName || (Prefix.Length != 0 && !reader.MapPrefixWithNamespace(Prefix)))) { return(false); //currently the AstNode build initial the name as String.Empty } return(true); }
internal override bool MatchNode(XPathReader reader) { if (NodeType == XPathNodeType.All) { return(true); } var ret = true; if (!MatchType(NodeType, reader.NodeType)) { ret = false; } else if (Name != null && (Name != reader.Name || Prefix != reader.Prefix)) { ret = false; } return(ret); }
static void Main(string[] args) { try{ XPathReader xpr = new XPathReader("books.xml", "//book/title"); while (xpr.ReadUntilMatch()) { Console.WriteLine(xpr.ReadString()); } Console.ReadLine(); }catch (XPathReaderException xpre) { Console.WriteLine("XPath Error: " + xpre); }catch (XmlException xe) { Console.WriteLine("XML Parsing Error: " + xe); }catch (IOException ioe) { Console.WriteLine("File I/O Error: " + ioe); } }
public static Dictionary <string, string> SelectMultiple(this IBaseMessage pInMsg, params string[] xPaths) { Stream inboundStream = pInMsg.BodyPart.GetOriginalDataStream(); var virtualStream = new VirtualStream(); var readOnlySeekableStream = new ReadOnlySeekableStream(inboundStream, virtualStream); readOnlySeekableStream.Seek(0, SeekOrigin.Begin); var xmlTextReader = new XmlTextReader(readOnlySeekableStream); var xPathCollection = new XPathCollection(); //Keep track of the mapping between XPaths and their position in the XPathCollection var indexToXPathMap = new Dictionary <int, string>(); foreach (var xPath in xPaths) { int index = xPathCollection.Add(xPath); indexToXPathMap.Add(index, xPath); } var xPathReader = new XPathReader(xmlTextReader, xPathCollection); var xPathToValueMap = new Dictionary <string, string>(); while (xPathReader.ReadUntilMatch()) { string value = xPathReader.NodeType == XmlNodeType.Attribute ? xPathReader.GetAttribute(xPathReader.Name) : xPathReader.ReadString(); //Which XPath triggered the match int index = indexToXPathMap.Keys.First(x => xPathReader.Match(x)); //Only return the first match for each XPath if (!xPathToValueMap.ContainsKey(indexToXPathMap[index])) { xPathToValueMap.Add(indexToXPathMap[index], value); } } readOnlySeekableStream.Seek(0, SeekOrigin.Begin); return(xPathToValueMap); }
/// <summary> /// Get the result of an XPath expression on the given message /// </summary> /// <param name="_XPathResultType">Whether the resulting node's value, name, or namspace should be treated as the result</param> /// <param name="_XPathQuery">The XPath Expression</param> /// <param name="exceptionIfNotFound">Whether or not to thrown an exception if the XPath expression does not evaluate</param> /// <returns>The result of an XPath expression on the given message</returns> public string GetXPathResult(XPathResultTypeEnum _XPathResultType, string _XPathQuery, bool exceptionIfNotFound) { XmlTextReader xmlTextReader = new XmlTextReader(base.InMsg.BodyPart.GetOriginalDataStream()); XPathCollection xPathCollection = new XPathCollection(); xPathCollection.Add(_XPathQuery); XPathReader xPathReader = new XPathReader(xmlTextReader, xPathCollection); bool isFound = false; string value = null; while (xPathReader.ReadUntilMatch()) { if (xPathReader.Match(_XPathQuery)) { isFound = true; switch (_XPathResultType) { case XPathResultTypeEnum.Name: value = xPathReader.LocalName; break; case XPathResultTypeEnum.Namespace: value = xPathReader.NamespaceURI; break; case XPathResultTypeEnum.Value: value = xPathReader.ReadString(); break; } } } if ((isFound == false) && (exceptionIfNotFound)) { base.SetException(new Exception("No result found for XPath query - " + _XPathQuery)); } base.InMsg.BodyPart.Data.Position = 0; return(value); }
public IEnumerable <ISearchResult> FindAllForwardOnly(ITextSource document, int offset, int length) { var xc = new XPathCollection(); try { xc.Add(_xPath); } catch (Exception) { yield break; } using (var reader = new XmlTextReader(document.CreateReader())) using (var xpathReader = new XPathReader(reader, xc)) { var lineInfo = xpathReader as IXmlLineInfo; var doc = (IDocument)document; ISegment segment; while (Read(xpathReader)) { if (xpathReader.Match(0) && xpathReader.NodeType != XmlNodeType.EndElement) { segment = null; try { segment = XmlSegment(doc, lineInfo.LineNumber, lineInfo.LinePosition); } catch (Exception) { } if (segment != null && segment.Offset >= offset && segment.EndOffset <= (offset + length)) { yield return(new XPathSearchResult() { StartOffset = segment.Offset, Length = segment.Length }); } } } } }
internal override object GetValue(XPathReader reader) { var n1 = Convert.ToDouble(Operand1.GetValue(reader)); var n2 = 0d; if (Op != Operator.Op.Negate) { n2 = Convert.ToDouble(Operand2.GetValue(reader)); } return(Op switch { Operator.Op.Plus => (n1 + n2), Operator.Op.Minus => (n1 - n2), Operator.Op.Mod => (n1 % n2), Operator.Op.Div => (n1 / n2), Operator.Op.Mul => (n1 * n2), Operator.Op.Negate => - n1, _ => null });
public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(IPipelineContext pContext, Microsoft.BizTalk.Message.Interop.IBaseMessage pInMsg) { IBaseMessagePart bodyPart = pInMsg.BodyPart; Stream inboundStream = bodyPart.GetOriginalDataStream(); VirtualStream virtualStream = new VirtualStream(0x280, 0x100000); ReadOnlySeekableStream readOnlySeekableStream = new ReadOnlySeekableStream(inboundStream, virtualStream, 0x280); XmlTextReader xmlTextReader = new XmlTextReader(readOnlySeekableStream); XPathCollection xPathCollection = new XPathCollection(); xPathCollection.Add("/*[local-name()='LFT' and namespace-uri()='http://Codit.LFT.Schemas']/*[local-name()='TempFile' and namespace-uri()='']"); XPathReader xPathReader = new XPathReader(xmlTextReader, xPathCollection); bool ok = false; string val = string.Empty; while (xPathReader.ReadUntilMatch()) { if (xPathReader.Match(0) && !ok) { val = xPathReader.ReadString(); ok = true; } } if (ok) { VirtualStream outboundStream = new VirtualStream(0x280, 0xA00000); using (FileStream fs = new FileStream(val, FileMode.Open, FileAccess.Read, FileShare.Read)) { byte[] buffer = new byte[4096]; int bytesRead = fs.Read(buffer, 0, buffer.Length); while (bytesRead != 0) { outboundStream.Write(buffer, 0, bytesRead); outboundStream.Flush(); bytesRead = fs.Read(buffer, 0, buffer.Length); } } outboundStream.Position = 0; bodyPart.Data = outboundStream; } return pInMsg; }
public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg) { bool terminate = true; IBaseMessagePart bodyPart = pInMsg.BodyPart; Stream inboundStream = bodyPart.GetOriginalDataStream(); VirtualStream virtualStream = new VirtualStream(VirtualStream.MemoryFlag.AutoOverFlowToDisk); ReadOnlySeekableStream readOnlySeekableStream = new ReadOnlySeekableStream(inboundStream, virtualStream); XmlTextReader xmlTextReader = new XmlTextReader(readOnlySeekableStream); XPathCollection xPathCollection = new XPathCollection(); XPathReader xPathReader = new XPathReader(xmlTextReader, xPathCollection); xPathCollection.Add(XPath); while (xPathReader.ReadUntilMatch()) { if (xPathReader.Match(0)) { terminate = false; inboundStream.Seek(0, SeekOrigin.Begin); break; } } if (terminate == true) { pInMsg = null; } return(pInMsg); }
public void generateChildren(XPathReader reader) { reader.MoveToContent(); int counter = 0; while (reader.ReadUntilMatch()) { switch (reader.NodeType) { case XmlNodeType.Element: //MessageBox.Show("element -> " + reader.Name); Element newElement = createModelElement(reader); TreeNodeViewModel newNode = new TreeNodeViewModel(newElement, this); //check if it has children if (reader.HasAttributes || !reader.IsEmptyElement) newNode.hasChildren = true; else newNode.hasChildren = false; newNode.IsExpanded = false; this.addChild(newNode); counter++; break; case XmlNodeType.Attribute: Element newAttr = createAttributeElement(reader); TreeNodeViewModel attrNode = new TreeNodeViewModel(newAttr, this); attrNode.hasChildren = false; attrNode.IsExpanded = false; //MessageBox.Show("attribute -> " + reader.Name + " : " + reader.Value); this.Children.Add(attrNode); counter++; break; case XmlNodeType.Text: Element newTextElement = createValueElement(reader); TreeNodeViewModel newTextElementNode = new TreeNodeViewModel(newTextElement, this); newTextElementNode.hasChildren = false; newTextElementNode.IsExpanded = false; //MessageBox.Show("text -> " + reader.Value); this.addChild(newTextElementNode); counter++; break; default: break; } if (counter > 10) break; } }
private void TreeViewItem_Expanded(object sender, RoutedEventArgs e) { TreeViewItem tvi = (TreeViewItem)e.Source; TreeNodeViewModel treeNode = (TreeNodeViewModel)tvi.Header; if (treeNode != null) { string xpathBase = treeNode.getXPath(); string xpath = xpathBase + "/child::*"; string xpath2 = xpathBase + "/attribute::*"; string xpath3 = xpathBase + "/text()"; XPathCollection xpc = new XPathCollection(); int query = xpc.Add(xpath); int query2 = xpc.Add(xpath2); int query3 = xpc.Add(xpath3); XPathReader xreader = new XPathReader(ModelTree.modelFile, xpc); //MessageBox.Show("expanded -> " + xpath); treeNode.generateChildren(xreader); e.Handled = true; } else MessageBox.Show("Nist agha!"); }
internal override bool MatchNode(XPathReader reader) => base.MatchNode(reader);
internal override object GetValue(XPathReader reader) => QueryInput.GetValue(reader);
internal override bool MatchNode(XPathReader reader) => _Query1.MatchNode(reader) || _Query2.MatchNode(reader);
internal override bool MatchNode(XPathReader reader) => false;