用于编辑 xml 标签中字符串的批处理脚本或 python 程序
我正在编写一个程序,用于搜索 xml 文档中的标签,并将标签之间的字符串从 localhost 更改为 manager。该标签可能会在xml文档中多次出现,并且文档确实有明确的路径。 python 还是 vbscript 对这个问题最有意义?谁能提供一个模板以便我可以开始使用?那太好了。谢谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果这是一件简单的事情,比如在这里或那里更改一些字符串,您可能可以使用 python 正则表达式完成所有操作,请检查此处:
对于更复杂的事情,我建议使用像 Beautiful Soup 这样的东西:
它有点过时,但包含您想要的所有内容曾经需要...
我同意这属于 stackoverflow.com,因为这是一个编程问题。
If it's a simple thing, like changing a few strings here and there, you might be able to do everything with a python regexp, check here:
For everything more complex, I would suggest using something like Beautiful Soup:
It's a bit outdated, but contains everything you would ever need...
I agree this belongs to stackoverflow.com, as it's a programming question.
我建议你直接去 python 的 lxml 库,不要回头。对 xml 的正则表达式操作可能会产生可怕的后果,而 BeautifulSoup 虽然相当流行,但已被正式放弃。
lxml
非常强大、快速且高效。对于您的任务,编写就足够了:您可以在 lxml 的文档中找到很多帮助:
http://lxml.de/
I suggest that you go straight to lxml library for python and don't look back. The regex manipulation of xml can have terrible consequences, and BeautifulSoup, although quite popular, is officially abandoned.
lxml
is quite powerfull, fast and efficient. For your task, it is sufficient to write:You can find a lot of help in lxml's documentation:
http://lxml.de/