I need to parse an XML file stored in the blobstore. How do I do that?
This is what I have done till now:
FileService fileService = FileServiceFactory.getFileService();
AppEngineFile file = fileService.getBlobFile(new BlobKey(key));
I cannot parse the XML file using javax.xml package or can I? The classes in that package if put into action requires a reference of a java.io.File object. But I do not have that.
This is what I have been doing till now : (not on the server but locally)
File blobKeys = new File("/home/non-admin/NetBeansProjects/Personal Site_Testers/web/xml/xml_1.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(blobKeys);
Element root = doc.getDocumentElement();
Element firstName = doc.createElement("first-name");
firstName.setTextContent(name);
root.appendChild(firstName);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File("/home/non-admin/NetBeansProjects/Personal Site_Testers/web/xml/xml_1.xml"));
transformer.transform(source, result);
Note : There are 3 xml files uploaded to the blobstore. Those xml files just have a root tag . I want to get the xml reference and parse them to append child node several times depending upon the request made.
If you want to parse *.xml, I think jdom2 may be is more convenient which I use in the app engine and it works.
However, you can read the FileService API document and there is an example with how to read and write the file. If you can get a InputStream or Reader, then you can use javax.xml to parse the xml content in the InputStream or Reader.