Hello again,

I have modified the sample code to see if I can add two files viz. a.xml and 
b.xml in an XDBC server running on my local machine. 

I am thinking if I can create a collection with URI as "user3" and add couple 
of content objects i.e. xml files to it then I should be view these two files 
when I query this database through CQ portal.

First the Code is  as follows:


a.xml contents:
<?xml version="1.0" encoding="UTF-8"?>
<hello-a>Hello World of MarkLogic- </hello-a>

b.xml contents:
<?xml version="1.0" encoding="UTF-8"?>
<hello-b>Hello World of MarkLogic</hello-b>


public class MultiContentLoader {
    private final Session session;
    private ContentCreateOptions options = null;

    public MultiContentLoader(URI serverUri) throws XccConfigException {
        ContentSource cs = ContentSourceFactory.newContentSource(serverUri);

        session = cs.newSession();
    }

    public void load(String[] uris, File[] files) throws RequestException {
        Content content = null;
     
        for (int i = 0; i < files.length; i++) {
                System.out.println("uri=["+uris[i]+"] file=["+files[i]+"]");
            options = ContentCreateOptions.newXmlInstance();
            options.setCollections(uris);
            options.setFormatXml();

                content = ContentFactory.newContent(uris[i], files[i], options);
            System.out.println("Inserting contents..");
            session.insertContent(content);
            session.commit();
        }
        
    }

    public void load(File[] files) throws RequestException {
        String[] uris = new String[files.length];

        for (int i = 0; i < files.length; i++) {
                uris[i] = "user3";
        }

        load(uris, files);
    }


    public static void main(String[] args) throws URISyntaxException, 
XccConfigException, RequestException {
        if (args.length < 2) {
            usage();
            return;
        }

        URI serverUri = new URI(args[0]);
        File[] files = new File[args.length - 1];

        for (int i = 0; i < files.length; i++) {
            files[i] = new File(args[i + 1]);
        }

        MultiContentLoader loader = new MultiContentLoader(serverUri);

        loader.load(files);

        System.out.println("Loaded " + files.length + " files ");
    }

    // ------------------------------------------------------

    private static void usage() {
        System.err.println("usage: serveruri docpath ...");
    }
}
 
I run above code by passing two files names a.xml and b.xml on command prompt.

The program runs successfully without any exceptions.

When I query the database using CQ and following query, I see an entry in 
database with "user3" which shows the contents of b.xml i.e. the last file in 
the list. 

Output is similar to below:
user3 – element hello-b (properties)  collections:user3

When I click on the collection:user3 link adjacent to it it returns empty i.e. 
there is nothing in it. 

The query I am running is as follows:
xquery version "1.0-ml";
(: buffer 1 :)
declare namespace html = "http://www.w3.org/1999/xhtml";;
for $line in collection(("user3"))  
return $line

I thought of trying this as per the documentation provided in Search 
developer's guide as well as in XCC/Java booklet.

I am sure that we should be able to programmatically (i.e. using XCC/J 
connector) to create a collection which has a URI i.e. user3 and a couple of 
documents i.e. a.xml and b.xml attached to it. The code does not work, so what 
is the missing bit?

Thanks
Babu


----- Original Message -----
From: Justin Makeig <justin.mak...@marklogic.com>
To: General MarkLogic Developer Discussion <general@developer.marklogic.com>
Sent: Wed, 26 Oct 2011 21:46:10 +0530 (IST)
Subject: Re: [MarkLogic Dev General] XML content and binary file needs to be 
joined and rendered on web page..

Babu,
URIs uniquely identify documents in a database, similar to a primary key in a 
relational database table. I’m not sure about your use case, but, like Mike 
outlined, I’d suggest creating the user document XCCDemo/user1 and the 
associated image at XCCDemo/user1/image. There are various ways you can 
associate the image with the related users. You could put both of those 
documents in the same collection (user1) or directory (as Mike indicates 
below). You could also put a reference to the image URI in the user1 XML 
document. If you could provide more details on what you’re trying to do, 
someone on the list might be able to give you some more specific advice. 

Justin



On Oct 26, 2011, at 9:05 AM, Babu Moshay wrote:

> Hi Michael/All,
> 
> I have managed to get XCC/Java samples working. Objective initially is to 
> insert two documents i.e. one xml and one image at common uri e.g. 
> XCCDemo/user1/ .
> 
> I tried following:
> Loop for 2 files:
>  contents[i] = ContentFactory.newContent(uris[i], files[i], options);
> 
> then,
> Session.insertContent(Content[])
> 
> But this overwrites the previous file and retains the last written file.
> 
> Which API would help achieving this? 
> 
> 
> Thanks
> BM
> 
> ----- Original Message -----
> From: Michael Blakeley <m...@blakeley.com>
> To: General MarkLogic Developer Discussion <general@developer.marklogic.com>
> Sent: Mon, 24 Oct 2011 21:46:53 +0530 (IST)
> Subject: Re: [MarkLogic Dev General] XML content and binary file needs to be 
> joined and rendered on web page..
> 
> You have a problem with that requirement "not to use XQuery". That's sort of 
> like saying "don't use SQL" with an RDBMS. Sure, you can encapsulate it so 
> that you cannot see it from your Java code - but it's still there. The XCC 
> connector doesn't write XQuery for you.
> 
> Thinking in terms of low-level RDBMS tools like foreign keys and tables won't 
> get you very far. Back up. Start from the use cases instead, and do some 
> top-down work. Think about per-user documents and directories. For example, 
> you might model each user as a URI prefix ('/user/' + USERID + '/') and store 
> each user's XML in a well-known URI with that prefix. Multiple XML or BLOB 
> documents might also share that prefix. You could then use xdmp:directory() 
> to query all of a user's documents, or doc() to retrieve a specific document. 
> I don't know if that really suits your use-cases, but it might.
> 
> Keep in mind that the XML data model does not provide for binary nodes: those 
> are a MarkLogic extension, and they are allowed only as root nodes. You can 
> store and retrieve both types of nodes in one update or query, though, so you 
> should be able to implement your use cases. You can probably implement 
> inserts without using XQuery, but you will have to write some XQuery to query 
> the database. That's what it's for.
> 
> -- Mike
> 
> On 24 Oct 2011, at 08:05 , Babu Moshay wrote:
> 
>> Dear all,
>> I am new to Marklogic setup as well as NoSQL way of doing things..I have a 
>> use-case which would have been very straightforward to implement in J2EE 
>> patterns using RDBMS but now that I am expected to evaluate MarkLogic I 
>> wonder if this mailing list can help me out with it....
>> 
>> I have looked through the documentation PDFs but haven't been able to figure 
>> out what exactly needs to be done to get going...
>> 
>> I have 2 tables...1 user details e.g. name of the user, contact etc 
>> etc..plus it has a BLOB which stores his picture...then there is another 
>> table which stores user's published articles(all BLOBs) which has userId as 
>> foreign key referencing user table's primary key..
>> 
>> I take input from frontend which accepts all these inputs from HTML form and 
>> create necessary entries in database..
>> 
>> I am told not to use XQuery ..Just use XCC/Java connector and see if that 
>> works...
>> I am looking for a tutorial or precise peace of document which discusses 
>> these activities...
>> 
>> I can store XML content....agreed..
>> I can store Binary content....agreed.
>> 
>> Can I write something which joins XML and Binary together and forms a single 
>> unit while reading/writing from Marklogic?
>> 
>> 
>> 
>> Thanks and regards,
>> BM
>> 
>> _______________________________________________
>> General mailing list
>> General@developer.marklogic.com
>> http://developer.marklogic.com/mailman/listinfo/general
> 
> _______________________________________________
> General mailing list
> General@developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
> 
> _______________________________________________
> General mailing list
> General@developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to