Hi,
I have a db that has all of my xml documents, I would like to make a bunch of new dbs based on the document types which map to the document element name so for example if I do the query /LOV I get back 115491 Items, I would then like to put that into a db named LOV. How do I put the outputs of query on one db into another db, and does anyone have some code that would go through every /* and create a db by the name of the document element if that db does not exist and then place the document into that DB - or would that be insanely process intensive (there are 290422 items, 13 document types)?
Thanks, Bryan Rasmussen
Dear Bryan,
we are currently including new db:create() and db:drop() functions to BaseX. Until then, there are other options to do what you want. One example is creating a command script from XQuery [1] and run it afterwards, e.g. as follows:
file:write('script.bxs', <commands>{ for $c in distinct-values(db:open('your-db')/*/name()) return <create-db name="{ $c }"/> }</commands>)
In the next step, you could add the documents to the newly created databases:
for $doc in db:open('Analysedocumentaire') let $name := $doc/*/name() return db:add($name, $doc)
Hope this helps, Christian
[1] http://docs.basex.org/wiki/Commands#Basics ___________________________
On Thu, Oct 25, 2012 at 2:19 PM, bryan rasmussen rasmussen.bryan@gmail.com wrote:
Hi,
I have a db that has all of my xml documents, I would like to make a bunch of new dbs based on the document types which map to the document element name so for example if I do the query /LOV I get back 115491 Items, I would then like to put that into a db named LOV. How do I put the outputs of query on one db into another db, and does anyone have some code that would go through every /* and create a db by the name of the document element if that db does not exist and then place the document into that DB - or would that be insanely process intensive (there are 290422 items, 13 document types)?
Thanks, Bryan Rasmussen _______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
In the next step, you could add the documents to the newly created databases:
for $doc in db:open('Analysedocumentaire') let $name := $doc/*/name() return db:add($name, $doc)
Since there doesn't seem to be any way around this, is there a way to find more info on the error:
Stopped at line 1, column 65: [FODC0007] Resource path '' is invalid.
Other possibilities I've tried:
Putting db:add in try-catch, doing a counter and an if with db:add inside of the if so that I could see if I could make it work for some files, unfortunately I guess neither of those scenarios is allowed - anyway to do something like that? Is there a way to do a query and export results to a filepath, and then import that filepath into my specific db.
Also when I look at the dbs I created they look like the following:
Database Properties Name: AFGDOK Size: 4540 Bytes Nodes: 1 Documents: 1 Binaries: 0 Timestamp: 25.10.2012 15:40:19
Resource Properties Timestamp: 25.10.2012 15:40:19 Encoding: UTF-8 Whitespace Chopping: ON
Indexes Up-to-date: true Text Index: ON Attribute Index: ON Full-Text Index: OFF
I never actually put a document in there, but it says it has a document, is that normal? I figured probably like there is some sort of hidden metadata document in every db?
Thanks, Bryan Rasmussen
Hi Bryan,
I noticed I overlooked an important detail in your query: there was no indication of how the target document should be called. The following query should work:
for $doc in db:open('AFGDOK') let $name := $doc/*/name() let $target := replace(base-uri($doc), '.*?/', '') return db:add($name, $doc, $target)
In the existing example, we have a document name, which is encoded in the base uri; but there are many examples in which no document name exists; e.g.:
db:add('db', document { <a/> }, 'name.xml")
However, I'll think about implicitly assigning the original document name if it exists. If this works out, the former query will work in future, too.
I never actually put a document in there, but it says it has a document, is that normal? I figured probably like there is some sort of hidden metadata document in every db?
Correct! This hidden document has been removed in the latest 7.5 snapshots [1].
Hope this helps, Christian
Hi Bryan,
I'm glad to tell I've updated the db:add() function; it now automatically detects and adopts original database document paths. Feel free to check out the latest stable snapshot [1].
Christian
[1] http://files.basex.org/releases/latest/ ___________________________
On Fri, Oct 26, 2012 at 1:22 PM, Christian Grün christian.gruen@gmail.com wrote:
Hi Bryan,
I noticed I overlooked an important detail in your query: there was no indication of how the target document should be called. The following query should work:
for $doc in db:open('AFGDOK') let $name := $doc/*/name() let $target := replace(base-uri($doc), '.*?/', '') return db:add($name, $doc, $target)
In the existing example, we have a document name, which is encoded in the base uri; but there are many examples in which no document name exists; e.g.:
db:add('db', document { <a/> }, 'name.xml")
However, I'll think about implicitly assigning the original document name if it exists. If this works out, the former query will work in future, too.
I never actually put a document in there, but it says it has a document, is that normal? I figured probably like there is some sort of hidden metadata document in every db?
Correct! This hidden document has been removed in the latest 7.5 snapshots [1].
Hope this helps, Christian
basex-talk@mailman.uni-konstanz.de