您的位置:软件 > 开发者网络 > 微软开发专栏 > Visual Studio.net专栏 > XML > 正文
XPath在无线应用中的实现(下)
[文章信息]
作者:wayne
时间:2003-04-01
出处:yesky
责任编辑:方舟
[文章导读]
在这一部分里,我们打算讨论XPath的更进一步的特性--在一个XML文件上执行复杂检索的操作
advertisement
热点推荐
· 11.15软件精选 制作MSI文件
· 闪客五周年之闪客光荣榜
· 用Winamp“品尝”无限音乐
· 网络加、解密的技术应用
· 闪客五周年之闪客光荣榜:zoron
[正文]

上一页  1 2 3 4  

  代码段3:

<?xml version="1.0" encoding="UTF-8" ?>
<wml>
 <!--简单的WML文件-->
 <card id="first">
  <p>
   First card.
  </p>
 </card>
 <card id="second">
  <p>
   First para of the Second card.
  </p>

  <p>
   Second para of the Second card.
  </p>

 </card>
 <!--可以在下面放入其它的card-->
</wml>

  代码段4:

public class XPathExpression
{
 DOM_Document XML_DOM;
 Array of Strings XPathLocationStepStringsArray;
 Array of XPathLocationSteps XPathLocationStepsArray;
 Array of XPathResults ResultNodeSet;

 XPathExpression (string XMLFile, string XPathExpression)
 {
  XML_DOM = XMLFile loaded into a DOM;
  FunctionName =
If there is any XPath function in the begining of the query,
store the function name here;
Strip the function name from the expression.

  XPathLocationStepStringsArray =
Tokenize XPath expression into smaller strings,
where each string is a location step.
Also unabbreviate any XPath abbreviations found;

  Integer locationStepCount = Number of location step strings
in XPathLocationStepStringsArray;
String IndividualXPathLocationStepString;
XPathLocationStep IndividualXPathLocationStep;

  ResultNodeSet = XML_DOM loaded into an array of XPathResults.

  Repeat locationStepCount times from i = 0 to locationStepCount-1:
  {
   IndividualXPathLocationStepString = XPathLocationStepStringsArray[i];
   IndividualXPathLocationStep = a new object of XPathLocationStep(
                  IndividualXPathLocationStepString,
                  XML_DOM
   );
   ResultNodeSet = IndividualXPathLocationStep.getResult(ResultNodeSet);
  }

  Apply the XPath function on the resulting node-set

 }

 XPathExpression (DOM_Document XML_DOM, string XPathExpression)
 {
  Same as the first constructor,
  except that it takes the XML file as a
  DOM object instead of a string.

 }

 public Array of XPathResults getResult()
 {
  return ResultNodeSet;
 }
}

  代码段5:

public class XPathLocationStep
{
 String Axis;
 String NodeTest;
 Array of XPathResults OutputNodeSet;
 String FunctionName;
 String Predicate;
 DOM_Document XML_DOM;

 XPathLocationStep(String XPathLocationStepString, DOM_Document XML_DOM_Document)
 {
  Resolve the XPathLocationStepString into FunctionName,
  Axis, NodeTest, and Predicate;
  XML_DOM = XML_DOM_Document;
 }

 Array of XPathResults getResult(Array of Nodes ContextNodeSet)
 {
  OutputNodeSet = new Array of XPathResults;

  Integer NodeCount =Number of nodes in ContextNodeSet;
  if (Axis is equal to "child" or "descendant")
  {
   Repeat NodeCount times for i = 0 to NodeCount-1
   {
    Node node = ContextNodeSet[i];
    Integer ChildCount = Number of node's children;
    Repeat ChildCount times for j = 0 to ChildCount-1
    {
     Node ChildNode =node.getChildElement(j);
     String ChldName =Name of the ChildNode;
     if (NodeTest is equal to ChildName)
      Add ChildNode to OutputNodeSet;
     if (Axis is equal to "descendant")
     {
      Array of Nodes Descendants =getMatchingDescendants(ChildNode);
      Add MatchingDescendants to OutputNodeSet;
     }
    }
   }
  }

  Predicate predicateEvaluator = new Predicate(OutputNodeSet, XML_DOM);
  OutputNodeSet = predicateEvaluator.getResult();
  return OutputNodeSet;

 }

 private Array of Nodes getMatchingDescendants(Node node)
 {
  Array of Nodes MatchingDescendants;
  Integer ChildCount = Number of node's children;
  Repeat NodeCount times for j = 0 to ChildCount-1
  {
   Node ChildNode =node.getChildElement(j);
   String ChildName =Name of the ChildNode;
   if (NodeTest is equal to ChildName)
    Add ChildNode to MatchingDescendants;

   Array of Nodes MoreDescendants =getMatchingDescendants(ChildNode);
   Add MoreDescendants to MatchingDescendnts;
  }
  return MatchingDescendants;
 }

}

  代码段6:

public class XPathResult
{ string ResultType = "ArrayOfNodes";

 string getResultType
 {
  return ResultType;

 }

 public setResultType (string Type)
 {
  ResultType = Type;
 }
}

  代码段7:

public class Predicate
{
 Array of XPathResults ResultSet;

 Predicate(Array of XPathResults ResultSet,
 DOM_Document XML_DOM)
 {
  Check if this predicate is just a logical condition or a complete XPath query.
  If it is a complete XPath expression
  {
   ResultSet = (new XPathExpression(XML_DOM, XPath Expression))
   .getResult();
  }
  else
  {
   ResultSet = Filtered result set;
  }
 
 }

 Array of XPathResults getResult()
 {
  return ResultSet;
 }

}


上一页  1 2 3 4  

·"WAP天极之IT新闻资讯,50万元等你拿"    ·天极WAP之游戏狂图,50万元等你下载


发表评论推荐给朋友我想参加相关培训打印我对此感兴趣订阅电子杂志
相关内容阅读排行榜
  • 11.15软件精选 制作MSI文件
  • 闪客五周年之闪客光荣榜
  • 兰欣推出我国第一款网络游戏专用音箱
  • 玩家发现117亡灵种族Bug
  • [配置推荐]极品HIFI配置
  • 东瀛美少女COSPLAY(55)
  • 用Winamp“品尝”无限音乐
  • 迷你型PStwo全面透析专题
  • Advertisement