Ron, thanks for the thoughtful response. I've since been able to get my arms around the concept of specifying the document uri and have moved on to some more advanced concepts. I used this XQuery tutorial once I was able to specify my documents. I downloaded all the source code and ran a few of the queries and I'm able to navigate my xml data now.
Your explanation of the URI was especially helpful. I see that when I explore the database that the URIs are listed, so I can copy and paste from those. I also moved my data to an easier location to type, since the data doesn't have to be relative to a root folder. Thanks again for your help. Scott ________________________________ From: Ron Hitchens <[email protected]> To: General MarkLogic Developer Discussion <[email protected]> Sent: Sun, April 3, 2011 2:29:31 PM Subject: Re: [MarkLogic Dev General] Working with loaded data Scott, A few things here. This code: xdmp:document-load( "/C/software/MarkLogic Server/db/people/people.xml", <options xmlns="xdmp:document-load"> <uri>/people</uri> <format>xml</format> </options> ) Reads the content from a file on disk named "/C/software/MarkLogic Server/db/people/people.xml", parses it as XML and stores that XML data structure as a document in MarkLogic referenced by the URI "/people". It does not implicitly add ".xml" to the URI because you indicated that the format is XML. In fact, the only relationship between the URI and the format is that the format is guessed from the URI's extension if you don't state it explicitly. The URI you provide is exactly the value used, even if might seem illogical to you. Document URIs are not filenames. The content is indexed and stored inside the MarkLogic database. The URI you supply is a retrieval key, it does not refer to a ".xml" file anywhere. Second, this module is invalid XQuery because you've tried to do two things (a function call and a FLWOR) without joining them as a sequence with a comma. XQuery is a functional language where everything is an expression, it's not a procedural series of instructions. Third, even if it were legal, this module would not do what you expect. An important aspect of functional languages is the lack of side-effects. There are some complexities in ML related to transactionality and update vs query requests, but the net effect is basically that an XQuery module cannot see its own updates. What that means in practice is that you can't load a document and then run a query on it in the same query. The point of MarkLogic is to run queries against a (potentially huge) content set that has been previously loaded and indexed. Load your content first, then run lots of queries against it afterward. All the lovely documentation can be found here: http://developer.marklogic.com/docs You may also find this helpful to get stated with XQuery: http://www.pragprog.com/titles/xquery/getting-started-with-xquery On Apr 3, 2011, at 3:26 PM, Scott wrote: > Ron, > > The URI worked great. Thanks! > > I tried using the xdmp:document-load() as you mentioned, but I'm still >struggling with the syntax and where to find the documentation. I downloaded >the entire documentation set, but I'm still finding my way around. > > This is what I tried as I understood your suggestion: > > xquery version "1.0-ml"; > xdmp:document-load( "/C/software/MarkLogic Server/db/people/people.xml", > <options xmlns="xdmp:document-load"> > <uri>/people</uri> > <format>xml</format> > </options> ) > for $person in doc( "/people/people.xml" )/people/person > return ( > <div> > $person/@name > <a href="delete.xqy?path={ xdmp:path($person) }">delete</a> > </div> > ) > > This is not correct syntax. > > But with the URI replacement you gave me I am in business. Thanks. > > Scott > > From: Ron Hitchens <[email protected]> > To: General MarkLogic Developer Discussion <[email protected]> > Sent: Sun, April 3, 2011 5:09:45 AM > Subject: Re: [MarkLogic Dev General] Working with loaded data > > > The name (actually the URI) of your document in > MarkLogic is "/C/software/MarkLogic Server/db/people/people.xml", > not simply "people.xml". > > A collection of documents in MarkLogic is not a > disk-style filesystem, even though it can often be > treated that way. Whenever you reference a specific > document by name you need to provide the full and > complete URI. Think of document URIs as more like > hash keys than filenames. > > Use the xdmp:document-load() function to load > a document and assign your preferred URI. > > On Apr 3, 2011, at 6:16 AM, Scott wrote: > > > I just downloaded MarkLogic Server 4.2 and have created a database and > > loaded >some data. I'm brand new to this, so I have a basic question on how to >specify >a document to query. > > > > I followed this tutorial for setting up a new database with the Shakespeare >data. But I'll go through a simple scenario of creating everything from >scratch. > > • Create a new database called "people" > > • Create a new forest called "people", no data directory specified > > • Create a new HTTP App Server called "people", specify a root folder, >port 8012, selected database "people" > > • Copy the cq folder from the samples folder > > • Copy an xml file to the http server root called people.xml. Here is > >the >contents: > > • <people> > > <person name="bob" /> > > <person name="jim" /> > > <person name="bob" /> > > <person name="ryan" /> > > </people> > > > > • I load the data using the load tab of the people database screen. > > • In CQ->explore, I see: /C/software/MarkLogic >Server/db/people/people.xml – element people (properties) (no collections) > > • Now I can query this data: > > xquery version "1.0-ml"; > > for $person in doc()/people/person > > return ( > > <div> > > $person/@name > > <a href="delete.xqy?path={ xdmp:path($person) }">delete</a> > > </div> > > ) > > > > > > There are some problems with this query that some research will help me to >figure out--the results look like this: > > > > > > $person/@name delete > > $person/@name delete > > $person/@name delete > > $person/@name delete > > > > > > --but I'm getting the right number of results. My question is, how to I >target a document by name? > > > > > > If I change the doc() call above to read doc( "people.xml" ), I get an > > emtpy >return set in response. I need this to work because I have several xml files >loaded into the database I'm trying to work with, and I want to be specific. > > > > > > Thanks for helping out! > > > > > > Scott > > > > > > _______________________________________________ > > General mailing list > > [email protected] > > http://developer.marklogic.com/mailman/listinfo/general > > --- > Ron Hitchens {mailto:[email protected]} Ronsoft Technologies > +44 7879 358 212 (voice) http://www.ronsoft.com > +1 707 924 3878 (fax) Bit Twiddling At Its Finest > "No amount of belief establishes any fact." -Unknown > > > > > _______________________________________________ > General mailing list > [email protected] > http://developer.marklogic.com/mailman/listinfo/general > _______________________________________________ > General mailing list > [email protected] > http://developer.marklogic.com/mailman/listinfo/general --- Ron Hitchens {mailto:[email protected]} Ronsoft Technologies +44 7879 358 212 (voice) http://www.ronsoft.com +1 707 924 3878 (fax) Bit Twiddling At Its Finest "No amount of belief establishes any fact." -Unknown _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
