【发布时间】:2012-09-04 03:38:16
【问题描述】:
我有以下 XML:
<test>
<something name="test">
<todo>Something is here!</todo>
</something>
<mytag id="myID">!!!!</mytag>
<todo>Hello, world</todo>
</test>
我需要替换一个标签的内容,其中包含id="myID" 并得到:
<test>
<something name="test">
<todo>Something is here!</todo>
</something>
<mytag id="myID">**MY NEW STRING IS HERE**</mytag>
<todo>Hello, world</todo>
</test>
有没有标准的方法来实现它?我知道xmerl_xs 是一种Erlang 的XML 转换方式。但它不能用来解决我的问题。
我只设法使用 Xmerl 获得了<mytag id="myID">**MY NEW STRING IS HERE**</mytag>。我的代码:
{ RootEl, _Rest } = xmerl_scan:string(Template),
[Match|_] = xmerl_xpath:string("//*[@id='myID']", RootEl),
% Pack new content to the container
Result = Match#xmlElement { content="**MY NEW STRING IS HERE**" }
是否只能使用非标准库(Sablotron 等)?
【问题讨论】: