本文整理汇总了C#中System.Xml.XPath.XPathNavigator.ComparePosition方法的典型用法代码示例。如果您正苦于以下问题:C# XPathNavigator.ComparePosition方法的具体用法?C# XPathNavigator.ComparePosition怎么用?C# XPathNavigator.ComparePosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XPath.XPathNavigator
的用法示例。
在下文中一共展示了XPathNavigator.ComparePosition方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
/// <summary>
/// Add a node indexed by the specified key value.
/// </summary>
public void Add(string key, XPathNavigator navigator) {
XmlQueryNodeSequence seq;
if (!this.table.TryGetValue(key, out seq)) {
// Create a new sequence and add it to the index
seq = new XmlQueryNodeSequence();
seq.AddClone(navigator);
this.table.Add(key, seq);
}
else {
// The nodes are guaranteed to be added in document order with possible duplicates.
// Add node to the existing sequence if it differs from the last one.
Debug.Assert(navigator.ComparePosition(seq[seq.Count - 1]) >= 0, "Index nodes must be added in document order");
if (!navigator.IsSamePosition(seq[seq.Count - 1])) {
seq.AddClone(navigator);
}
}
}
示例2: MoveNext
/// <summary>
/// Position this iterator to the next preceding node in document order. Discard all input nodes
/// that are followed by another input node in the same document. This leaves one node per document from
/// which the complete set of preceding nodes can be derived without possibility of duplicates.
/// Return IteratorResult.NeedInputNode if the next input node needs to be fetched first. Return
/// IteratorResult.HaveCurrent if the Current property is set to the next node in the iteration.
/// </summary>
public IteratorResult MoveNext(XPathNavigator input)
{
switch (_state)
{
case IteratorState.NeedCandidateCurrent:
// If there are no more input nodes, then iteration is complete
if (input == null)
return IteratorResult.NoMoreNodes;
// Save input node as current node
_navCurrent = XmlQueryRuntime.SyncToNavigator(_navCurrent, input);
// Scan for additional input nodes within the same document (since they are after navCurrent in docorder)
_state = IteratorState.HaveCandidateCurrent;
return IteratorResult.NeedInputNode;
case IteratorState.HaveCandidateCurrent:
// If there are no more input nodes,
if (input == null)
{
// Then candidate node has been selected, and there are no further input nodes
_state = IteratorState.HaveCurrentNoNext;
}
else
{
// If the input node is in the same document as the current node,
if (_navCurrent.ComparePosition(input) != XmlNodeOrder.Unknown)
{
// Then update the current node and get the next input node
_navCurrent = XmlQueryRuntime.SyncToNavigator(_navCurrent, input);
return IteratorResult.NeedInputNode;
}
// Save the input node as navNext
_navNext = XmlQueryRuntime.SyncToNavigator(_navNext, input);
_state = IteratorState.HaveCurrentHaveNext;
}
PushAncestors();
break;
}
if (!_navStack.IsEmpty)
{
while (true)
{
// Move to the next matching node that is before the top node on the stack in document order
if (_filter.MoveToFollowing(_navCurrent, _navStack.Peek()))
// Found match
return IteratorResult.HaveCurrentNode;
// Do not include ancestor nodes as part of the preceding axis
_navCurrent.MoveTo(_navStack.Pop());
// No more preceding matches possible
if (_navStack.IsEmpty)
break;
}
}
if (_state == IteratorState.HaveCurrentNoNext)
{
// No more nodes, so iteration is complete
_state = IteratorState.NeedCandidateCurrent;
return IteratorResult.NoMoreNodes;
}
// Make next node the current node and start trying to find input node greatest in docorder
_navCurrent = XmlQueryRuntime.SyncToNavigator(_navCurrent, _navNext);
_state = IteratorState.HaveCandidateCurrent;
return IteratorResult.HaveCurrentNode;
}
示例3: CompareNodes
public static XmlNodeOrder CompareNodes(XPathNavigator l, XPathNavigator r)
{
XmlNodeOrder cmp = l.ComparePosition(r);
if (cmp == XmlNodeOrder.Unknown)
{
XPathNavigator copy = l.Clone();
copy.MoveToRoot();
string baseUriL = copy.BaseURI;
if (!copy.MoveTo(r))
{
copy = r.Clone();
}
copy.MoveToRoot();
string baseUriR = copy.BaseURI;
int cmpBase = string.CompareOrdinal(baseUriL, baseUriR);
cmp = (
cmpBase < 0 ? XmlNodeOrder.Before :
cmpBase > 0 ? XmlNodeOrder.After :
/*default*/ XmlNodeOrder.Unknown
);
}
return cmp;
}
示例4: AddKeyValue
private static void AddKeyValue(Hashtable keyTable, String key, XPathNavigator value, bool checkDuplicates) {
ArrayList list = (ArrayList)keyTable[key];
if (list == null) {
list = new ArrayList();
keyTable.Add(key, list);
} else {
Debug.Assert(
value.ComparePosition((XPathNavigator) list[list.Count - 1]) != XmlNodeOrder.Before,
"The way we traversing nodes should garantees node-order"
);
if (checkDuplicates) {
// it's posible that this value already was ----osiated with current node
// but if this happened the node is last in the list of values.
if (value.ComparePosition((XPathNavigator) list[list.Count - 1]) == XmlNodeOrder.Same) {
return;
}
} else {
Debug.Assert(
value.ComparePosition((XPathNavigator) list[list.Count - 1]) != XmlNodeOrder.Same,
"checkDuplicates == false : We can't have duplicates"
);
}
}
list.Add(value.Clone());
}
示例5: AddResult
private void AddResult(ArrayList ResultList, XPathNavigator nav) {
int count = ResultList.Count;
for(int i = 0; i< count; i++ ) {
XmlNodeOrder docOrder = nav.ComparePosition(((XPathNavigator)ResultList[i] ));
if (docOrder == XmlNodeOrder.Same){
return;
}
if (docOrder == XmlNodeOrder.Before) {
ResultList.Insert(i, nav.Clone());
return;
}
}
ResultList.Add(nav.Clone());
}
示例6: CompareNodes
public static XmlNodeOrder CompareNodes(XPathNavigator l, XPathNavigator r)
{
XmlNodeOrder order = l.ComparePosition(r);
if (order != XmlNodeOrder.Unknown)
{
return order;
}
XPathNavigator navigator = l.Clone();
navigator.MoveToRoot();
string baseURI = navigator.BaseURI;
if (!navigator.MoveTo(r))
{
navigator = r.Clone();
}
navigator.MoveToRoot();
string strB = navigator.BaseURI;
int num = string.CompareOrdinal(baseURI, strB);
return ((num < 0) ? XmlNodeOrder.Before : ((num > 0) ? XmlNodeOrder.After : XmlNodeOrder.Unknown));
}
示例7: IsInDependenciesMap
/// <summary>
/// Checks an XPathNavigator object to see if it's already in the dependency
/// map. Contains won't work with XPathNavigator objects that point
/// to the same node, you see.
/// </summary>
/// <param name="node">The node to test.</param>
/// <returns>true if it's on the list.</returns>
private bool IsInDependenciesMap(XPathNavigator node)
{
foreach (DependencyList next in this.dependencyMap)
{
if (node.ComparePosition(next.Node) == XmlNodeOrder.Same)
{
return true;
}
}
return false;
}
示例8: IsContextUsed
private bool IsContextUsed(XPathNavigator contextNode)
{
foreach (XPathNavigator nav in this.usedContext)
{
if (contextNode.ComparePosition(nav) == System.Xml.XmlNodeOrder.Same)
{
return true;
}
}
return false;
}