0

I need to retrieve all items in the SimpleDB domain from java application. So, I used the select method, but I don't know is there an easy way to store the retrieved values in an xml file?? or I've to create the attributes and elements by myself and set values to them, like this:

        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

        Document doc = docBuilder.newDocument();
        Element rootElement = doc.createElement("Items");
        doc.appendChild(rootElement);

    SelectRequest selectRequest = new SelectRequest(selectExpression);

        for (Item item : sdb.select(selectRequest).getItems()) {
            //  <item>-------------------
            itemBeg = doc.createElement("Item");
            rootElement.appendChild(itemBeg);
                //  <Name>-------------------
                Elmname = doc.createAttribute("Name");
                Elmname.setValue(item.getName());
                itemBeg.setAttributeNode(Elmname);
                  //  <Attributes> -----------------
                attrib = doc.createElement("Attributes");
                itemBeg.appendChild(attrib);

             for (Attribute attribute : item.getAttributes()) {
                //  attribute <Name> -----------------
                 attrName = doc.createAttribute("Name");
                attrName.setValue(attribute.getName());
                attrib.setAttributeNode(attrName);
                 //  attribute <Value> -------------------
                    attrValue = doc.createAttribute("Value");
                attrValue.setValue(attribute.getValue());
                attrib.setAttributeNode(attrValue);
            }
ebt_dev
  • 149
  • 1
  • 3
  • 12
  • `Amazon SimpleDB` return its `response` in `XML` so if you print `response` in console to will see all `Items`, `Attributes` and `Values` in `XML` format. To debug and get that response, you have to include `JAVA AWS Code` instead of `Java AWS JAR` in your project. – Ashish Pancholi Mar 10 '14 at 04:56
  • When I print the response in console, I get the output like this {Items: [{Name: Item_01,Attributes: [{Name: Name,Value: Cathair Sweater,}, {Name: Category,Value: Clothes,}]}. – ebt_dev Mar 10 '14 at 07:46
  • The output does not looks like the xml file formate (there is no tags). How I can convert it to xml formate to be easier to read from it?? Thanks.. – ebt_dev Mar 10 '14 at 10:57
  • I was talking about, to print the an `http response body` as a string. Please debug the `Java AWS Source Code` and see what you are getting in the `http response`. I think that should be in `XML`. – Ashish Pancholi Mar 11 '14 at 11:15
  • I'm sorry, I don't got it. Could you give more explanation please.. what do you mean by including Java AWS Code instead of JAR. I'm creating a new AWS project in eclipse and running SimpleDb [sample code](https://code.google.com/p/localservice/source/browse/trunk/SampleAmazonSimpleDB/src/SimpleDBSample.java?spec=svn16&r=16) – ebt_dev Mar 12 '14 at 10:07

0 Answers0