// // The function context node has to be the axis selected node // <E a='1' xmlns='test'> <E1/> </E> // // /E/E1[namespaceuri(../E)= 'test'] internal override object GetValue(XPathReader reader) { object ret = null; // the Opnd must be attribute, otherwise it will be in error switch (this.funcType) { case FT.FuncCount: ret = reader.AttributeCount; break; case FT.FuncPosition: //we need to go back to the fileter query to get count ret = base.PositionCount; break; case FT.FuncNameSpaceUri: ret = reader.NamespaceURI; break; case FT.FuncLocalName: ret = reader.LocalName; break; case FT.FuncName : ret = reader.Name; break; } return ret; }
// // walk through all the queries to see // if any query matches with the current // read // internal void Advance(XPathReader reader) { foreach (XPathQuery expr in this) { expr.Advance(reader); } }
// // predicate could be result in two results type // 1). Number: postion query // 2). Boolean // internal override bool MatchNode(XPathReader reader) { bool ret = false; if (this.axis.MatchNode(reader)) { if (reader.NodeType != XmlNodeType.EndElement && reader.ReadMethod != ReadMethods.MoveToElement) { ++matchCount; // // send postion information down to the prdicates // this.predicate.PositionCount = matchCount; } object obj = this.predicate.GetValue(reader); if (obj is System.Boolean && Convert.ToBoolean(obj) == true) { ret = true; } else if (obj is System.Double && Convert.ToDouble(obj) == matchCount) { //we need to know how many this axis has been evaluated ret = true; } else if (obj != null && !(obj is System.Double || obj is System.Boolean) ){ //object is nodeset ret = true; } } return ret; }
// // // internal override object GetValue(XPathReader reader) { object obj = new object(); switch (_FuncType) { case FT.FuncBoolean: obj = toBoolean(reader); break; case FT.FuncNot: obj = Not(reader); break; case FT.FuncTrue: obj = true; break; case FT.FuncFalse: obj = false; break; case FT.FuncLang: obj = Lang(reader); break; } return(obj); }
// // 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 Boolean toBoolean(XPathReader reader) { Boolean ret = true; object obj = _qy.GetValue(reader); if (obj is System.Double) { double number = Convert.ToDouble(obj); if (number == 0 || number == double.NaN) { ret = false; } } else if (obj is System.String) { if (obj.ToString().Length == 0) { ret = false; } } else if (obj is System.Boolean) { ret = Convert.ToBoolean(obj); } else if (obj == null && reader.NodeType != XmlNodeType.EndElement) { ret = false; } return(ret); } // toBoolean
internal override object GetValue(XPathReader reader) { double n1 = 0, n2 = 0; n1 = Convert.ToDouble(this.opnd1.GetValue(reader)); if (this.op != Operator.Op.NEGATE) { n2 = Convert.ToDouble(this.opnd2.GetValue(reader)); } switch (this.op) { case Operator.Op.PLUS: return(n1 + n2); case Operator.Op.MINUS: return(n1 - n2); case Operator.Op.MOD: return(n1 % n2); case Operator.Op.DIV: return(n1 / n2); case Operator.Op.MUL: return(n1 * n2); case Operator.Op.NEGATE: return(-n1); } return(null); }
String Normalize(XPathReader reader) { String str1; if (this.argList != null && this.argList.Count > 0) { str1 = ((IQuery)this.argList[0]).GetValue(reader).ToString().Trim(); } else { str1 = String.Empty; } int count = 0; StringBuilder str2 = new StringBuilder();; bool FirstSpace = true; while (count < str1.Length) { if (!XmlCharType.IsWhiteSpace(str1[count])) { FirstSpace = true; str2.Append(str1[count]); } else if (FirstSpace) { FirstSpace = false; str2.Append(str1[count]); } count++; } return(str2.ToString()); }
// // The function context node has to be the axis selected node // <E a='1' xmlns='test'> <E1/> </E> // // /E/E1[namespaceuri(../E)= 'test'] internal override object GetValue(XPathReader reader) { object ret = null; // the Opnd must be attribute, otherwise it will be in error switch (this.funcType) { case FT.FuncCount: ret = reader.AttributeCount; break; case FT.FuncPosition: //we need to go back to the fileter query to get count ret = base.PositionCount; break; case FT.FuncNameSpaceUri: ret = reader.NamespaceURI; break; case FT.FuncLocalName: ret = reader.LocalName; break; case FT.FuncName: ret = reader.Name; break; } return(ret); }
String Translate(XPathReader reader) { String str1 = ((IQuery)this.argList[0]).GetValue(reader).ToString(); String str2 = ((IQuery)this.argList[1]).GetValue(reader).ToString(); String str3 = ((IQuery)this.argList[2]).GetValue(reader).ToString(); StringBuilder str = new StringBuilder(); int count = 0, index; while (count < str1.Length) { index = str2.IndexOf(str1[count]); if (index != -1) { if (index < str3.Length) { str.Append(str3[index]); } } else { str.Append(str1[count]); } count++; } return(str.ToString()); }
// // predicate could be result in two results type // 1). Number: postion query // 2). Boolean // internal override bool MatchNode(XPathReader reader) { bool ret = false; if (this.axis.MatchNode(reader)) { if (reader.NodeType != XmlNodeType.EndElement && reader.ReadMethod != ReadMethods.MoveToElement) { ++matchCount; // // send postion information down to the prdicates // this.predicate.PositionCount = matchCount; } object obj = this.predicate.GetValue(reader); if (obj is System.Boolean && Convert.ToBoolean(obj) == true) { ret = true; } else if (obj is System.Double && Convert.ToDouble(obj) == matchCount) { //we need to know how many this axis has been evaluated ret = true; } else if (obj != null && !(obj is System.Double || obj is System.Boolean)) //object is nodeset { ret = true; } } return(ret); }
Boolean Startswith(XPathReader reader) { String str1 = ((IQuery)this.argList[0]).GetValue(reader).ToString(); String str2 = ((IQuery)this.argList[1]).GetValue(reader).ToString(); return(str1.StartsWith(str2)); }
// // boolean lang(string) // private Boolean Lang(XPathReader reader) { String str = _qy.GetValue(reader).ToString(); String lang = reader.XmlLang.ToLower(); return(lang.Equals(str) || str.Equals(lang.Split('-')[0])); }
// // internal override object GetValue(XPathReader reader) { object obj = new object(); switch (_FuncType) { case FT.FuncNumber: obj = Number(reader); break; // case FT.FuncSum: // obj = Sum(reader); // break; case FT.FuncFloor: obj = Floor(reader); break; case FT.FuncCeiling: obj = Ceiling(reader); break; case FT.FuncRound: obj = Round(reader); break; } return(obj); }
Double StringLength(XPathReader reader) { if (this.argList != null && this.argList.Count > 0) { return(((IQuery)this.argList[0]).GetValue(reader).ToString().Length); } return(0); }
private double Round(XPathReader reader) { double n = Convert.ToDouble(_qy.GetValue(reader)); // Math.Round does bankers rounding and Round(1.5) == Round(2.5) == 2 // This is incorrect in XPath and to fix this we are useing Math.Floor(n + 0.5) istead // To deal with -0.0 we have to use Math.Round in [0.5, 0.0] return((-0.5 <= n && n <= 0.0) ? Math.Round(n) : Math.Floor(n + 0.5)); }
internal override bool MatchNode(XPathReader reader) { if (this.query1.MatchNode(reader)) { return(true); } return(this.query2.MatchNode(reader)); }
internal void AdvanceUntil(XPathReader reader) { Advance(reader); if (compiledXPath[matchIndex] is AttributeQuery) { reader.ProcessAttribute = reader.Depth + 1; // the attribute depth should be current element plus one } }
// // <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) { object[] objArray; objArray = new object[2]; objArray[0] = this.query1.GetValue(reader); objArray[1] = this.query2.GetValue(reader); return((object)objArray); }
internal override object GetValue(XPathReader reader) { object ret = this.opnd1.GetValue(reader); if (Convert.ToBoolean(ret) == true) { ret = this.opnd2.GetValue(reader); } return(ret); }
String Concat(XPathReader reader) { int count = 0; StringBuilder s = new StringBuilder(); while (count < this.argList.Count) { s.Append(((IQuery)this.argList[count++]).GetValue(reader).ToString()); } return(s.ToString()); }
internal override object GetValue(XPathReader reader) { if (reader.HasValue) { return((object)reader.Value); } else { throw new XPathReaderException("Can't get the element value"); } }
Boolean Contains(XPathReader reader) { String str1 = ((IQuery)this.argList[0]).GetValue(reader).ToString(); String str2 = ((IQuery)this.argList[1]).GetValue(reader).ToString(); int index = str1.IndexOf(str2); if (index != -1) { return(true); } return(false); }
// // walk through all the queries to see // if any query matches with the current // read // internal void AdvanceUntil(XPathReader reader) { foreach (XPathQuery expr in this) { expr.AdvanceUntil(reader); } if (!CurrentContainAttributeQuery()) { reader.ProcessAttribute = -1; } }
internal override object GetValue(XPathReader reader) { object ret = this.opnd1.GetValue(reader); if (Convert.ToBoolean(ret) == false) { ret = this.opnd2.GetValue(reader); } #if DEBUG1 Console.WriteLine("OrExpr: {0}", ret); #endif return(ret); }
// The reader will be the current element node // We need to restore the internal override object GetValue(XPathReader reader) { XmlReader baseReader = reader.BaseReader; object ret = null; if (baseReader.MoveToAttribute(base.Name)) { ret = reader.Value; } //Move back to the parent baseReader.MoveToElement(); return ret; }
internal override object GetValue(XPathReader reader) { object obj = new object(); switch (this.funcType) { case FT.FuncString: obj = toString(reader); break; case FT.FuncConcat: obj = Concat(reader); break; case FT.FuncStartsWith: obj = Startswith(reader); break; case FT.FuncContains: obj = Contains(reader); break; case FT.FuncSubstringBefore: obj = Substringbefore(reader); break; case FT.FuncSubstringAfter: obj = Substringafter(reader); break; case FT.FuncSubstring: obj = Substring(reader); break; case FT.FuncStringLength: obj = StringLength(reader); break; case FT.FuncNormalize: obj = Normalize(reader); break; case FT.FuncTranslate: obj = Translate(reader); break; } return(obj); }
// // number number(object?) // string: IEEE 754, NaN // boolean: true 1, false 0 // node-set: number(string(node-set)) // // <Root><e a='1'/></Root> // /Root/e[@a=number('1')] // /Root/e[number(@a)=1] private double Number(XPathReader reader) { if (_qy != null) { object obj = _qy.GetValue(reader); if (obj == null) { return(double.NaN); } return(Convert.ToDouble(obj)); } return(double.NaN); }
String Substringafter(XPathReader reader) { String str1 = ((IQuery)this.argList[0]).GetValue(reader).ToString(); String str2 = ((IQuery)this.argList[1]).GetValue(reader).ToString(); int index = str1.IndexOf(str2); if (index != -1) { return(str1.Substring(index + str2.Length)); } else { return(String.Empty); } }
// // we need to walk the attribute for // query like e/@a and position the reader to that // attribute node. // example: e/attribute::node() // e/attribute::text() //no return // e/@a // // There are two situations to match the attributes // 1). user has moved the reader to an attribute in the current element context // 2). user still in the element context, since it's an attribute query, we // need to move to the attribute ourself. internal override bool MatchNode(XPathReader reader) { bool ret = true; if (base.NodeType != XPathNodeType.All) { if (!MatchType(base.NodeType, reader.NodeType)) { ret = false; } else if (base.Name != string.Empty && (base.Name != reader.Name || base.Prefix != reader.Prefix)) { ret = false; } } return ret; }
// The reader will be the current element node // We need to restore the internal override object GetValue(XPathReader reader) { XmlReader baseReader = reader.BaseReader; object ret = null; if (baseReader.MoveToAttribute(base.Name)) { ret = reader.Value; } //Move back to the parent baseReader.MoveToElement(); return(ret); }
internal override object GetValue(XPathReader reader) { object obj = new object(); switch (this.funcType) { case FT.FuncString : obj = toString(reader); break; case FT.FuncConcat : obj = Concat(reader); break; case FT.FuncStartsWith : obj = Startswith(reader); break; case FT.FuncContains : obj = Contains(reader); break; case FT.FuncSubstringBefore : obj = Substringbefore(reader); break; case FT.FuncSubstringAfter : obj = Substringafter(reader); break; case FT.FuncSubstring : obj = Substring(reader); break; case FT.FuncStringLength : obj = StringLength(reader); break; case FT.FuncNormalize : obj = Normalize(reader); break; case FT.FuncTranslate : obj = Translate(reader); break; } return obj; }
// // string string(object?) // object // node-set: string value of the first node // node-set = null, String.Empty return // number: NaN -> "NaN" // +0->"0", -0->"0", // +infinity -> "Infinity" -infinity -> "Infinity" // boolean: true -> "ture" false -> "false" // // Example: <Root><e a1='1' a2='2'/>text1</e> // <e a='12'> text2</e> // </Root> // /Root/e[string(self::node())="text"] // /Root/e[string(attribute::node())='1'] // /Root[string(/e)="text"] private String toString(XPathReader reader) { if (this.argList != null && this.argList.Count > 0) { IQuery query = (IQuery)this.argList[0]; object obj = query.GetValue(reader); if (obj == null) { return(String.Empty); } return(obj.ToString()); } return(String.Empty); }
internal override bool MatchNode(XPathReader reader) { bool ret = true; if (base.NodeType != XPathNodeType.All) { if (!MatchType(base.NodeType, reader.NodeType)) { ret = false; } else if (base.Name != null && (base.Name != reader.Name || base.Prefix != reader.Prefix)) { ret = false; } } return(ret); }
// In the query expression, we need to be // store the depth of tree that we have treversed // we shouldn't move the reader, if we move to the // an attribute, we need to move it back internal void Advance(XPathReader reader) { ResetMatching(reader); if ((IQuery)compiledXPath[matchIndex] is DescendantQuery) { //look through the subtree for the node is //looking for if (((IQuery)compiledXPath[matchIndex + 1]).MatchNode(reader)) { //found the node that we were looking for ((BaseAxisQuery)compiledXPath[matchIndex + 1]).Depth += reader.Depth - 1; matchIndex = matchIndex + 2; matchCount = matchIndex; //set the expected depth for the rest of query for (int i = matchCount; i < compiledXPath.Count - 1; ++i) { ((BaseAxisQuery)compiledXPath[matchIndex]).Depth += reader.Depth - 1; } } else { return; } } while (reader.Depth == ((BaseAxisQuery)compiledXPath[matchIndex]).Depth) { if (((IQuery)compiledXPath[matchIndex]).MatchNode(reader)) { ++matchIndex; matchCount = matchIndex; } else { //--matchIndex; break; } } SetMatchState(reader); }
bool CompareAsNumber(XPathReader reader) { double n1 = 0, n2=0; object opndVar1, opndVar2; opndVar1 = this.opnd1.GetValue(reader); opndVar2 = this.opnd2.GetValue(reader); try { n1 = Convert.ToDouble(opndVar1); n2 = Convert.ToDouble(opndVar2); } catch (System.Exception) { return false; } switch (op) { case Operator.Op.LT : if (n1 < n2) return true; break; case Operator.Op.GT : if (n1 > n2) return true; break; case Operator.Op.LE : if (n1 <= n2) return true; break; case Operator.Op.GE : if (n1 >= n2) return true; break; case Operator.Op.EQ : if (n1 == n2) return true; break; case Operator.Op.NE : if (n1 != n2) return true; break; } return false; }
// try to match the node internal override bool MatchNode(XPathReader reader) { bool ret = true; if (base.NodeType != XPathNodeType.All) { if (!MatchType(base.NodeType, reader.NodeType)) { ret = false; } else if (base.Name != string.Empty && (base.Name != reader.LocalName || (base.Prefix.Length != 0 && reader.MapPrefixWithNamespace(base.Prefix) == false))) { //currently the AstNode build initial the name as String.Empty ret = false; } } return(ret); }
String Substringafter(XPathReader reader) { String str1 = ((IQuery)this.argList[0]).GetValue(reader).ToString(); String str2 = ((IQuery)this.argList[1]).GetValue(reader).ToString(); int index = str1.IndexOf(str2); if (index != -1) return str1.Substring(index+str2.Length); else return String.Empty; }
Boolean Contains(XPathReader reader) { String str1 = ((IQuery)this.argList[0]).GetValue(reader).ToString(); String str2 = ((IQuery)this.argList[1]).GetValue(reader).ToString(); int index = str1.IndexOf(str2); if (index != -1) return true; return false; }
Boolean Startswith(XPathReader reader) { String str1 = ((IQuery)this.argList[0]).GetValue(reader).ToString(); String str2 = ((IQuery)this.argList[1]).GetValue(reader).ToString(); return str1.StartsWith(str2); }
String Concat(XPathReader reader) { int count = 0; StringBuilder s = new StringBuilder(); while (count < this.argList.Count) s.Append(((IQuery)this.argList[count++]).GetValue(reader).ToString()); return s.ToString(); }
} // toBoolean // // boolean not(boolean) // private Boolean Not(XPathReader reader) { Boolean ret = toBoolean(reader); return !ret; }
// // // internal override object GetValue(XPathReader reader) { object obj = new object(); switch (_FuncType) { case FT.FuncBoolean : obj = toBoolean(reader); break; case FT.FuncNot : obj = Not(reader); break; case FT.FuncTrue : obj = true; break; case FT.FuncFalse : obj = false; break; case FT.FuncLang : obj = Lang(reader); break; } return obj; }
private double Ceiling(XPathReader reader) { return Math.Ceiling(Convert.ToDouble(_qy.GetValue(reader))); }
// // internal override object GetValue(XPathReader reader) { object obj = new object(); switch (_FuncType) { case FT.FuncNumber: obj = Number(reader); break; // case FT.FuncSum: // obj = Sum(reader); // break; case FT.FuncFloor: obj = Floor(reader); break; case FT.FuncCeiling: obj = Ceiling(reader); break; case FT.FuncRound: obj = Round(reader); break; } return obj; }
String Normalize(XPathReader reader) { String str1; if (this.argList != null && this.argList.Count > 0) str1 = ((IQuery)this.argList[0]).GetValue(reader).ToString().Trim(); else str1 = String.Empty; int count = 0; StringBuilder str2 = new StringBuilder();; bool FirstSpace = true; while (count < str1.Length) { if (!XmlCharType.IsWhiteSpace(str1[count])) { FirstSpace = true; str2.Append(str1[count]); } else if (FirstSpace) { FirstSpace = false; str2.Append(str1[count]); } count++; } return str2.ToString(); }
String Substring(XPathReader reader) { String str1 = ((IQuery)this.argList[0]).GetValue(reader).ToString(); double num = Math.Round(Convert.ToDouble(((IQuery)this.argList[1]).GetValue(reader))) - 1; if (double.IsNaN(num)) return String.Empty; if (this.argList.Count == 3) { double num1 = Math.Round(Convert.ToDouble(((IQuery)this.argList[2]).GetValue(reader))) ; if (double.IsNaN(num1)) return String.Empty; if (num < 0) { num1 = num + num1; if (num1 <= 0) return String.Empty; num = 0; } double maxlength = str1.Length - num; if (num1 > maxlength) num1 = maxlength; return str1.Substring((int)num,(int)num1); } if (num < 0) num = 0; return str1.Substring((int)num); }
Double StringLength(XPathReader reader) { if (this.argList != null && this.argList.Count > 0) { return((IQuery)this.argList[0]).GetValue(reader).ToString().Length; } return 0; }
// // Look if the current query match what we have found // Two conditions to evaluate a match // 1). matchingIndex points to the end of query // 2). the depth of the tree matches the depth of the query internal void SetMatchState(XPathReader reader) { if (matchIndex < 1) { return; } int queryCount = compiledXPath.Count - 1; // take out the null query; int queryDepth = ((BaseAxisQuery)compiledXPath[matchIndex - 1]).Depth; if (matchCount == queryCount && queryDepth == reader.Depth) { matchState = true; } #if DEBUG1 Console.WriteLine("\nMatch query: {0}", xpath); Console.WriteLine("MatchCount {0}, query count{1}", matchCount, queryCount); Console.WriteLine("reader depth {0}, queryDepth{1}", matchCount, queryCount); Console.WriteLine("Name: {0}", reader.Name); Console.WriteLine("matchState {0}", matchState); #endif }
String Translate(XPathReader reader) { String str1 = ((IQuery)this.argList[0]).GetValue(reader).ToString(); String str2 = ((IQuery)this.argList[1]).GetValue(reader).ToString(); String str3 = ((IQuery)this.argList[2]).GetValue(reader).ToString(); StringBuilder str = new StringBuilder(); int count = 0, index; while (count < str1.Length) { index = str2.IndexOf(str1[count]); if (index != -1) { if (index < str3.Length) str.Append(str3[index]); } else str.Append(str1[count]); count++; } return str.ToString(); }
// // Reset the matching index if the reader move to the // node depth less than the expected depth // internal void ResetMatching(XPathReader reader) { matchState = false; // reset the matching index int count = compiledXPath.Count; if (reader.Depth < ((BaseAxisQuery)compiledXPath[matchIndex]).Depth) { matchIndex = depthLookup[reader.Depth]; matchCount = matchIndex + 1; } if (matchCount == count - 1 && matchIndex > 0) { --matchCount; --matchIndex; } #if DEBUG1 Console.WriteLine("\nResetMatchingIndex: {0}\n", xpath); Console.WriteLine("matchIndex: {0}, matchCount {1}, compiledXPath.Count {2}", matchIndex, matchCount, count); #endif }
// // number number(object?) // string: IEEE 754, NaN // boolean: true 1, false 0 // node-set: number(string(node-set)) // // <Root><e a='1'/></Root> // /Root/e[@a=number('1')] // /Root/e[number(@a)=1] private double Number(XPathReader reader) { if (_qy != null ) { object obj = _qy.GetValue(reader); if (obj == null) { return double.NaN; } return (Convert.ToDouble(obj)); } return double.NaN; }
// In the query expression, we need to be // store the depth of tree that we have treversed // we shouldn't move the reader, if we move to the // an attribute, we need to move it back internal void Advance(XPathReader reader) { ResetMatching(reader); if ((IQuery)compiledXPath[matchIndex] is DescendantQuery) { //look through the subtree for the node is //looking for if (((IQuery)compiledXPath[matchIndex+1]).MatchNode(reader)){ //found the node that we were looking for ((BaseAxisQuery)compiledXPath[matchIndex+1]).Depth += reader.Depth - 1; matchIndex = matchIndex + 2; matchCount = matchIndex; //set the expected depth for the rest of query for (int i = matchCount; i < compiledXPath.Count - 1; ++i) { ((BaseAxisQuery)compiledXPath[matchIndex]).Depth += reader.Depth -1; } } else { return; } } while (reader.Depth == ((BaseAxisQuery)compiledXPath[matchIndex]).Depth) { if (((IQuery)compiledXPath[matchIndex]).MatchNode(reader)) { ++matchIndex; matchCount = matchIndex; } else { //--matchIndex; break; } } SetMatchState(reader); }
private double Floor(XPathReader reader) { return Math.Floor(Convert.ToDouble(_qy.GetValue(reader))); }
internal void AdvanceUntil(XPathReader reader) { Advance(reader); if (compiledXPath[matchIndex] is AttributeQuery) { reader.ProcessAttribute = reader.Depth + 1; // the attribute depth should be current element plus one } }
private double Round(XPathReader reader) { double n = Convert.ToDouble(_qy.GetValue(reader)); // Math.Round does bankers rounding and Round(1.5) == Round(2.5) == 2 // This is incorrect in XPath and to fix this we are useing Math.Floor(n + 0.5) istead // To deal with -0.0 we have to use Math.Round in [0.5, 0.0] return (-0.5 <= n && n <= 0.0) ? Math.Round(n) : Math.Floor(n + 0.5); }
// // walk through all the queries to see // if any query matches with the current // read // internal void Advance(XPathReader reader) { foreach (XPathQuery expr in this) { expr.Advance(reader); } }
// // 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 Boolean toBoolean(XPathReader reader) { Boolean ret = true; object obj = _qy.GetValue(reader); if (obj is System.Double) { double number = Convert.ToDouble(obj); if (number == 0 || number == double.NaN) { ret = false; } } else if (obj is System.String) { if (obj.ToString().Length == 0) { ret = false; } } else if (obj is System.Boolean) { ret = Convert.ToBoolean(obj); } else if (obj == null && reader.NodeType != XmlNodeType.EndElement) { ret = false; } return ret; } // toBoolean
// // walk through all the queries to see // if any query matches with the current // read // internal void AdvanceUntil(XPathReader reader) { foreach (XPathQuery expr in this) { expr.AdvanceUntil(reader); } if (!CurrentContainAttributeQuery()) { reader.ProcessAttribute = -1; } }
// // boolean lang(string) // private Boolean Lang(XPathReader reader) { String str = _qy.GetValue(reader).ToString(); String lang = reader.XmlLang.ToLower(); return (lang.Equals(str) || str.Equals(lang.Split('-')[0])); }
// // string string(object?) // object // node-set: string value of the first node // node-set = null, String.Empty return // number: NaN -> "NaN" // +0->"0", -0->"0", // +infinity -> "Infinity" -infinity -> "Infinity" // boolean: true -> "ture" false -> "false" // // Example: <Root><e a1='1' a2='2'/>text1</e> // <e a='12'> text2</e> // </Root> // /Root/e[string(self::node())="text"] // /Root/e[string(attribute::node())='1'] // /Root[string(/e)="text"] private String toString(XPathReader reader) { if (this.argList != null && this.argList.Count > 0) { IQuery query = (IQuery) this.argList[0]; object obj = query.GetValue(reader); if (obj == null) { return String.Empty; } return obj.ToString(); } return String.Empty; }