伯克利 XML DB "where"模拟



我目前正在研究伯克利XML DB,并获得了使用它编写Python脚本的作业。我目前面临的问题是选择容器的特定节点。例如,我们有具有此类信息的容器

<root>
  <lab>
    <name>Lab1</name>
    <state>Completed</state>
  </lab>
  <lab>
    <name>Lab3</name>
    <state>Not completed</state>
  </lab>
</root>

如何使用特定<name>选择<lab>元素?在SQL中,我会使用WHERE Name='Lab1'。有什么方法可以在XML BDB中执行类似的操作?

我认为您最好获取旧文档,复制数据,删除文档并使用修改后的数据添加新文档。

mgr = XmlManager()
uc = mgr.createUpdateContext()
container = mgr.openContainer("labs.dbxml")  # Here must be your database name
qc = mgr.createQueryContext()
document = container.getDocument("Lab11")
name = document.getName()
content = document.getContent()
# Change fields here using XPath
container.deleteDocument('La1 1', uc)
container.putDocument(name, content, uc)

最新更新