是否可以使用 Jython 和 dom4j 在元素之间添加元素?
刚刚在玩 dom4j,非常棒。 我做了一年半的 PHP 开发人员,刚刚找到一份新工作并开始使用 Jython,现在我有空闲时间,它是一门很棒的语言。 正在考虑尝试在元素之间添加一个元素,如下所示:
<div id="content">
<p>Some text in here</p>
<!--New p tag here-->
<p>Some text in here</p>
</div>
是否可以在两个元素之间插入另一个 p 标签,而不将 DOM 转换为字符串并再次返回 DOM,因为这是我能做到的唯一方法是什么?
Just playing with dom4j, excellent. I was a PHP developer for a year and half, just got a new job and started playing around with Jython now I have spare time, its a great language. Was thinking about trying to add a element in between element, example below:
<div id="content">
<p>Some text in here</p>
<!--New p tag here-->
<p>Some text in here</p>
</div>
Is it possible to insert another p tag in between the two without converting the DOM to a string and back to DOM again as this is the only way I have been able to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对 dom4j 具体了解不多,但我会这样做:
div#content
的所有子节点复制到列表中,然后删除其子节点。div#content
节点中。p
节点插入到div#content
节点中。div#content
节点中。我不知道这在 DOM 方面是什么,但如果节点表示为 Jythonic 对象,那么应该很容易做到这一点。
I don't know much about dom4j specifically, but I would do it like this:
div#content
into a list, then delete its children.div#content
node.p
node into thediv#content
node.div#content
node.I don't know what this would be in terms of the DOM, but if nodes are represented as Jythonic objects, then it should be easy to do this.