Andrew Nikolin
Andrew Nikolin

Reputation: 307

Berkeley XML DB "where" analog

I'm currently studying Berkeley XML DB and got an assignment to write Python script using it. The problem I'm currently facing is to select specific node of container. For example we have container with such information

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

How to select <lab> element with specific <name>? In SQL I'd use WHERE Name='Lab1'. Is there any way to do something like that in XML BDB?

Upvotes: 0

Views: 52

Answers (1)

Maxim Bondarchuk
Maxim Bondarchuk

Reputation: 23

I think you better get old document, copy data, remove document and add new with modified data.

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)

Upvotes: 0

Related Questions