当前位置: 首页 > news >正文

DOM and XPATH

DOM

  • Originally developed for HTML. Supported by most browsers.

  • Represents the content of the XML or HTML document as a tree structure.

  • Using DOM, we can easily read and update the contents of the document.

D: Document —> file

O: Object —> tags elements

M: Model —> layout structure

Online DOM viewer:

Live DOM Viewer

XPATH

  • Allows us to use path expressions to navigate an XML document.

  • It allow us to select only the nodes we're interested in.

its :

  • Expression language.

  • Contains some standard functions.

  • Non-XML

XPATH works on the following kinds of nodes:

ExpressionDescription
nodenameSelects all nodes with the name"nodename"
/Selects from the root node
//Selects nodes in the document from the current node that match the selection no matter where they are
.Selects the value of the current node
..Selects the parent of the current node
@Selects attributes

Predicates

  • similar to filters

  • They always appear in[]

  • They appear after the axis and node text

Path ExpressionResult
/bookstore/book[1]Selects the first book element that is the child of the bookstore element.
/bookstore/book[last()]Selects the last book element that is the child of the bookstore element
/bookstore/book[last()-1]Selects the last but one book element that is the child of the bookstore element
/bookstore/book[position()<3]Selects the first two book elements that are children of the bookstore element
//title[@lang]Selects all the title elements that have an attribute named lang
//title[@lang='en']Selects all the title elements that have a "lang" attribute with a value of "en"
/bookstore/book[price>35.00]Selects all the book elements of the bookstore element that have a price element
/bookstore/book[price>35.00]/titleSelects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00

XPATH Axes

an Axes represents a relationship to the current node on the tree.

AxisNameResult
ancestorSelects all ancestors (parent, grandparent, etc.) of the current node
ancestor-or-selfSelects all ancestors (parent, grandparent, etc.) of the current node and the current node itself
attributeSelects all attributes of the current node
childSelects all children of the current node
descendantSelects all descendants (children, grandchildren, etc.) of the current node
descendant-or-selfSelects all descendants (children, grandchildren, etc.) of the current node and the current node itself
followingSelects everything in the document after the closing tag of the current node
following-siblingSelects all siblings after the current node
namespaceSelects all namespace nodes of the current node
parentSelects the parent of the current node
precedingSelects all nodes that appear before the current node in the document, except ancestors, attribute nodes and namespace nodes
preceding-siblingSelects all siblings before the current node
selfSelects the current node

相关文章:

  • linux中主从复制的架构和读写分离的方式
  • SpaceDesk如何连接平板/PC(生产力副屏)
  • 禁止选择当天及以后的时间
  • Prometheus node_exporter计算CPU利用率的标准公式应该是哪一个
  • 如何与听力损失者沟通
  • kafka发送大消息
  • 【开源】基于JAVA的学校热点新闻推送系统
  • 时间和空间复杂度
  • 设计测试用例
  • 3分钟了解安全数据交换系统有什么用!
  • 360勒索病毒:了解最新变种.360,以及如何保护您的数据
  • 升压斩波电路的simulink建模与仿真
  • 外卖系统开发:构建高效、安全的外卖平台
  • Arduino/Android 蓝牙通信系统设计解决方案
  • 面试心得总结ing版
  • 模式识别与机器学习(十):梯度提升树
  • Iceberg: COW模式下的MERGE INTO的执行流程
  • 【小白攻略】php 小数转为百分比,保留两位小数的函数
  • FFmpeg常见命令行
  • 【知识点随笔分享 | 第九篇】常见的限流算法
  • 两部门发布山洪灾害气象预警:北京西部、河北西部等局地山洪可能性较大
  • 洞天寻隐·学林纪丨玉洞桃源:仇英青绿山水画中的洞天与身体
  • 老铺黄金拟配售募资近27亿港元,用于门店拓展扩建及补充流动资金等
  • 对话哭泣照被恶意盗用成“高潮针”配图女生:难过又屈辱
  • 谜语的强制力:弗洛伊德与俄狄浦斯
  • 印巴局势快速升级,外交部:呼吁印巴以和平稳定的大局为重