xpath 相关问题

XPath的主要目的是解决XML文档的各个部分。它还提供操纵弦乐,数字和布尔值的基本设施。 XPath使用紧凑的非XML语法。 XPath在XML文档的抽象逻辑结构上运行,而不是表面语法。





XPath将所有子节点作为XMLgroovy

1 ... 我正在xml下方接收到请求

回答 1 投票 0

如何获得消失的信息的CSS选择器

https://automationexercise.com/login

回答 0 投票 0

如何在EventViewer XPath查询中抑制多个数据元素?

我想过滤Windows事件日志,以获取KCC或两个IP地址生成的事件。 这适用于KCC过滤器: <QueryList> <Query Id="0" Path="ADAM (ADLDS-HHT)"> <Select Path="ADAM (ADLDS-HHT)"> *[System[(EventID=1644)]] </Select> <Suppress Path="ADAM (ADLDS-HHT)"> *[EventData[Data='KCC']] </Suppress> </Query> </QueryList> 现在,我需要添加IP地址。 它们只是作为数据元素存储在事件中: <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <EventID Qualifiers="16384">1644</EventID> [other values remove for brevity] </System> <EventData> <Data>192.168.0.1:64790</Data> <Data>0</Data> <Data>0</Data> [other values remove for brevity] </EventData> </Event> 我已经为抑制部分尝试了一下: <Suppress Path="ADAM (ADLDS-HHT)"> *[EventData[Data='KCC' OR Data='192.168.1.2' OR Data='10.1.2.3']] </Suppress> 和此: <Suppress Path="ADAM (ADLDS-HHT)"> *[EventData[Data='KCC'] OR [Data='192.168.1.2'] OR [Data='10.1.2.3']] </Suppress> 但两者都没有工作。 我已经在线搜索,但是几乎所有示例都具有这样的属性名称:*[EventData[Data[@Name='TargetUserName']但是我的只是数据值 nbxpath语言对病例敏感;您想要的布尔操作员是or,而不是OR。 lmc也正确地指出,您需要忽略<Data>元素中的端口号。我不建议使用starts-with函数,因为当您排除10.1.2.30时,您不想排除10.1.2.3。在我的示例中,我使用substring-before函数来修剪端口规范。 *[ EventData[ Data='KCC' or substring-before(Data, ':') = '192.168.1.2' or substring-before(Data, ':') = '10.1.2.3' ] ] 我不会运行Windows,我无法正确测试它,但这就是我猜您的问题。

回答 1 投票 0


XPATH删除属性

hi任何人都知道使用XPath删除Attrbute。 特别是从链接中的rel属性及其文本。 即,我想删除rel ='一些文本'。 我正在解析HTML中的多个链接。

回答 4 投票 0


XPATH属性并不总是有效,并且给出无效的谓词

数据分为2个实验,每个实验具有2个波长(和更多的子节点)。我可以为波长选择一个属性,它为我提供了读数,没有任何问题,但是对于两个实验来说。如果我还尝试为波长选择一个属性,我将获得“ Xpathevalerror:无效谓词”错误。

回答 0 投票 0

XPath打印相同的值不正确

,但是,每个元素都有多个类别具有相同名称的类,这使XPath重复相同的值。

回答 2 投票 0

Pythonlxml.html syntaxerror:使用lxmlfind

以下Python代码提出了一个例外:

回答 1 投票 0


如何仅使用xpath 3.1?

我有一个戏剧的XML文件,该提取物将提供: lysistrata的cal.tu Mecastor salve。 sed quid

回答 1 投票 0

我如何检查以前缀开头的属性(不是属性值),并以后缀

1 <tr _ngcontent-hse-63=""> <td _ngcontent-hse-63=""> <span _ngcontent-hse-63="">1</span> </td> <td _ngcontent-hse-63=""> <span _ngcontent-hse-63="" class="noBr">CKH HOLDINGS</span> </td> </tr> 我有上述内容,我希望在硒中提取TD元素。但是,似乎NGCONTENT和数字之间的三个字母是随机的。我已经基于类似的问题尝试了以下问题:ref: By.xpath("//td[starts-with(@_ngcontent, '_ngcontent-') and ends-with(@_ngcontent, '-63')]"); 尽管@_ngcontent甚至不匹配任何属性,但我不太确定如何继续,我认为starting-with()和end-with()将与属性值匹配,而不是属性本身。 无论如何在那里解决这个问题吗?由于页面上还有很多其他元素,因此不可能使用TD元素。 BROWSER仅支持XPATH 1.0,不支持ends-with()。 您不能在硒中使用它。因此,您必须使用contains()您想通过以下XPath来实现您要做的事情。 //@*[starts-with(name(),'_ngcontent-') and contains(name(),'-63')]/parent::td iT选择具有以_ngcontent-并包含-63的属性的所有TD元素。

回答 1 投票 0

XPath如何处理XML名称空间?

XPath如何处理XML名称空间? 如果我使用 /IntuitResponse/QueryResponse/Bill/Id 要解析下面的XML文档,我将获得0个节点。 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2016-10-14T10:48:39.109-07:00"> <QueryResponse startPosition="1" maxResults="79" totalCount="79"> <Bill domain="QBO" sparse="false"> <Id>=1</Id> </Bill> </QueryResponse> </IntuitResponse> ,但是,我不是在XPath中指定名称空间(即http://schema.intuit.com/finance/v3不是路径的每个令牌的前缀)。如果我不明确地说,XPath怎么会知道我想要哪个?我想在这种情况下(因为只有一个名称空间)XPath可以完全忽略Id。但是,如果有多个名称空间,情况可能会变得丑陋。 XPATH 1.0/2.0定义XPath中的名称空间(推荐) XPath本身没有办法将命名空间前缀绑定到名称空间。 此类设施由托管库提供。 建议您使用这些设施并定义命名空间前缀,然后将其用于符合XML元素和属性名称,必要 the是XPath主机为指定名称空间前缀绑定到名称空间uris的各种机制中的一些机制。 (OP的原始Xpath,xmlns已被省入/IntuitResponse/QueryResponse/Bill/Id)。 C#: /IntuitResponse/QueryResponse Google张 / Google文档:不幸的是,XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("i", "http://schema.intuit.com/finance/v3"); XmlNodeList nodes = el.SelectNodes(@"/i:IntuitResponse/i:QueryResponse", nsmgr); 不提供名称空间前缀结合机制。 有关如何将IMPORTXML()用作工作的方法。 java(萨克斯): local-name() java(xpath): NamespaceSupport support = new NamespaceSupport(); support.pushContext(); support.declarePrefix("i", "http://schema.intuit.com/finance/v3"); 记者打电话 xpath.setNamespaceContext(new NamespaceContext() { public String getNamespaceURI(String prefix) { switch (prefix) { case "i": return "http://schema.intuit.com/finance/v3"; // ... } }); . 也看到: java xpath:使用默认名称空间xmlns查询 javascript: 看到用户定义的命名空间解析器:: DocumentBuilderFactory.setNamespaceAware(true) 注意,如果默认名称空间具有定义的关联名称空间前缀,则使用function nsResolver(prefix) { var ns = { 'i' : 'http://schema.intuit.com/finance/v3' }; return ns[prefix] || null; } document.evaluate( '/i:IntuitResponse/i:QueryResponse', document, nsResolver, XPathResult.ANY_TYPE, null ); 返回的nsResolver()可以消除对客户的需求。 Perl(libxml): Document.createNSResolver() Python(lxml):nsResolver() Python(elementTree): my $xc = XML::LibXML::XPathContext->new($doc); $xc->registerNs('i', 'http://schema.intuit.com/finance/v3'); my @nodes = $xc->findnodes('/i:IntuitResponse/i:QueryResponse'); Python(scrapy): from lxml import etree f = StringIO('<IntuitResponse>...</IntuitResponse>') doc = etree.parse(f) r = doc.xpath('/i:IntuitResponse/i:QueryResponse', namespaces={'i':'http://schema.intuit.com/finance/v3'}) PHP: 使用domdocument@tomalak的回答::namespaces = {'i': 'http://schema.intuit.com/finance/v3'} root.findall('/i:IntuitResponse/i:QueryResponse', namespaces) 还请参见php simplexmlnamespacepacespacespaces.。 ruby(Nokogiri): response.selector.register_namespace('i', 'http://schema.intuit.com/finance/v3') response.xpath('/i:IntuitResponse/i:QueryResponse').getall() 注意,诺科吉里支持删除名称空间, $result = new DOMDocument(); $result->loadXML($xml); $xpath = new DOMXpath($result); $xpath->registerNamespace("i", "http://schema.intuit.com/finance/v3"); $result = $xpath->query("/i:IntuitResponse/i:QueryResponse"); 但请参见下面的警告,阻碍了XML名称空间的击败。 VBA: puts doc.xpath('/i:IntuitResponse/i:QueryResponse', 'i' => "http://schema.intuit.com/finance/v3") VB.NET: doc.remove_namespaces! soapui(doc): xmlNS = "xmlns:i='http://schema.intuit.com/finance/v3'" doc.setProperty "SelectionNamespaces", xmlNS Set queryResponseElement =doc.SelectSingleNode("/i:IntuitResponse/i:QueryResponse") XMLSTARLET: xmlDoc = New XmlDocument() xmlDoc.Load("file.xml") nsmgr = New XmlNamespaceManager(New XmlNameTable()) nsmgr.AddNamespace("i", "http://schema.intuit.com/finance/v3"); nodes = xmlDoc.DocumentElement.SelectNodes("/i:IntuitResponse/i:QueryResponse", nsmgr) XSLT: declare namespace i='http://schema.intuit.com/finance/v3'; /i:IntuitResponse/i:QueryResponse 一旦您宣布了名称空间前缀,可以写入xpath以使用它: -N i="http://schema.intuit.com/finance/v3" the xpath中的命名空间(不建议)替代方法是编写测试反对<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:i="http://schema.intuit.com/finance/v3"> ... 的谓词: /i:IntuitResponse/i:QueryResponse 或在XPath 2.0中:local-name() 以这种方式刺激命名空间,但不推荐,因为它是 在不指定的完整元素/属性名称中。 the以区分不同的元素/属性名称 名称空间(名称空间的目的)。 请注意,可以通过添加其他谓词来明确检查命名空间URI:可以解决此问题: /*[local-name()='IntuitResponse']/*[local-name()='QueryResponse'] thanks to丹尼尔·海利(DanielHaley) 过多详细 XPATH 3.0/3.1 支持现代XPath 3.0/3.1的灯塔和工具直接在XPATH表达式中指定名称空间URI: /*:IntuitResponse/*:QueryResponse 虽然比使用XML名称空间前缀更详细,但它具有独立于主机库的名称空间前缀绑定机制的优势。 /*[ namespace-uri()='http://schema.intuit.com/finance/v3' and local-name()='IntuitResponse'] /*[ namespace-uri()='http://schema.intuit.com/finance/v3' and local-name()='QueryResponse'] 符号在其发起人詹姆斯·克拉克(James Clark)之后被称为clark符号。 W3C XPATH 3.1 EBNF语法称其为namespace-uri()。 thanks to MichaelKay为涵盖XPath 3.0/3.1的建议。

回答 1 投票 0

XPATH选择多个元素

我有一个XML,如下所示: 我希望xpath选择所有p name@class 我能够使用以下方式获得其他值: @version-上课 *[name()='list']/*[name()='p']-获取版本 *[name()='p']/@name-获得“电源” identificationCode-获取*[name()='p'](第一个p名)identificationCode-获得operationalState -9999a的值 与最后两个字段相似,我想使用XPath获取其余元素: position -1 serialNumber -1 unitId -8888b p -1 我怎么做? 如果您想从所有name元素中获取所需的数据,而不指定每个属性值,则可以使用 //list/following-sibling::p[@name] 或 //*[name()="list"]/following-sibling::*[name()="p" and @name] 如果您需要name属性值和p的文本内容: //list/following-sibling::p[@name]/@name | //list/following-sibling::p[@name] 有2个位置,您在步骤get-data-from-xml中指定xpath表达式: 循环XPath(内容选项卡)旨在通过返回Nodelist来从文档中得出行。 字段XPath(字段选项卡)旨在填充一行的字段。 如果您的文档在不同级别上包含多个节点级别,则最好针对最深的列表。 使用轴或..操作员访问祖先信息很容易。 当Xpath返回nodelist时,水壶将始终选择第一个项目而不是中断。 显然,您必须将//p用作循环XPath。 您可以尝试遵循XPath以检索XML中的任何“ P”元素,无论其位于XML中的位置,都具有特定的“名称”属性。 //p[@name='unitType'] here//是后代或自我。只需将Unitsype String替换为所需的一个。 上述XPATH选择的输出将为 <p name="unitType">HHHH</p>

回答 3 投票 0


XPATH-找到所有标签 - 与 我使用剧作家,我有以下HTML代码:

某些文本 我正在使用剧作家,我有以下HTML代码: <body> <custom-element-a>some text</custom-element-a> <custom-element-b>some text</custom-element-b> <custom-element-foo>some text</custom-element-foo> <custom-element-bar>some text</custom-element-bar> </body> <

回答 1 投票 0

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.