如何通过xpath按名称获取root或指定节点?

时间:2016-10-07 13:16:06

标签: php xml xpath

需要获取按名称指定的节点。例如,它应该如何查找节点'命令'或根节点?

这是我写的

type loggers =
    abstract member warn: Printf.StringFormat<'a, unit> -> 'a
    abstract member err: Printf.StringFormat<'a, unit> -> 'a

let getLoggers (log: log4net.ILog) = 
  { new loggers with
    member this.warn format = Printf.ksprintf log.Warn format
    member this.err format = Printf.ksprintf log.Error format }

let logs = getLoggers (log4net.LogManager.GetLogger("Log"))

logs.warn "This is a warning"
logs.warn "Something is wrong: %s" someString

其中{% for post in site.posts offset:9 %} {% if post.categories contains 'mycat' %} {{ post.title }} {% endif %} {% endfor %}

这是我得到的

        $xpath = "/ns0:StandardBusinessDocument/eanucc:message/eanucc:transaction/command";
        $xpath .= "/eanucc:documentCommand/documentCommandOperand/ns1:catalogueItemNotification/catalogueItem";
        $xpath .= "/catalogueItemChildItemLink/catalogueItem/catalogueItemChildItemLink/catalogueItem/tradeItem";
        $xpath .= "/tradeItemIdentification/gtin[.='$gtin']/";

UPD:我可以得到这样的节点

$gtin = 00000075032814

但如果我要走高 - 又有两个节点'catalogueItem',我得到一个xpath错误。

1 个答案:

答案 0 :(得分:1)

根节点:/*

按名称命名的节点://*[local-name() = 'command']//command(假设它们位于正确的XML命名空间中)

https://www.w3.org/TR/xpath/#function-local-name