我需要从java应用程序中检索SimpleDB域中的所有项目。所以,我使用了select方法,但我不知道是否有一种简单的方法可以将检索到的值存储在xml文件中?或者我自己创建属性和元素并为它们设置值,如下所示:
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);
}