举个例子:
<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"呢?有没有一种干净的方法可以做到这一点?
提前谢谢你!
您想在本例中使用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"
尝试使用 Haskell XPath 和:
/*/pou[body[SFC]]
进一步参考"XPath 查找具有特定子节点的所有元素"