2

举个例子:

<pous>
  <pou>
    <interface>
      ...
    </interface>
    <body>
      <FBD>
        ...
      </FBD>
    </body>
  </pou>
  <pou>
    <interface>
      ...
    </interface>
    <body>
      <SFC>
        ...
      </SFC>
    </body>
  </pou>
</pous>

我知道如何使用 atTag 函数获取所有“pou”:

atTag:: (ArrowXml a) => String -> a XmlTree XmlTree
atTag tag = deep (isElem >>> hasName tag)

但是如何只提取带有 SFC 标签的“pou”?有干净的方法吗?

先感谢您!

4

2 回答 2

1

您想filterA用于此示例

application
    = processChildren
    $ getChildren                    -- Gets the children of "pous"
    >>> filterA hasSFC
    where hasSFC =  hasName "pou"    -- Include all "pou" elements
                >>> getChildren      -- that have children
                >>> getChildren      -- that have children
                >>> hasName "SFC"    -- that have a "SFC" element

main = do
    runX $
        readDocument [] "input.xml" >>>
        application                 >>>
        writeDocument [withIndent yes] "output.xml"
于 2015-04-24T14:29:21.873 回答
0

尝试使用Haskell XPath并:

/*/pou[body[SFC]]

进一步参考“XPath 查找具有特定子节点的所有元素”

于 2015-04-24T13:58:55.227 回答