How do I convert a org.w3c.dom.Document object to a String?

use some thing like import java.io.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; //method to convert Document to String public String getStringFromDocument(Document doc) { try { DOMSource domSource = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.transform(domSource, result); return writer.toString(); } catch(TransformerException ex) … Read more

How do I load an org.w3c.dom.Document from XML in a string?

Whoa there! There’s a potentially serious problem with this code, because it ignores the character encoding specified in the String (which is UTF-8 by default). When you call String.getBytes() the platform default encoding is used to encode Unicode characters to bytes. So, the parser may think it’s getting UTF-8 data when in fact it’s getting … Read more

How to get the size of single document in Mongodb?

In the previous call of Object.bsonsize(), Mongodb returned the size of the cursor, rather than the document. Correct way is to use this command: Object.bsonsize(db.test.findOne()) With findOne(), you can define your query for a specific document: Object.bsonsize(db.test.findOne({type:”auto”})) This will return the correct size (in bytes) of the particular document.

Create a folder inside documents folder in iOS apps

I do that the following way: NSError *error; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@”/MyFolder”]; if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder

MongoDB: How to update multiple documents with a single command?

Multi update was added recently, so is only available in the development releases (1.1.3). From the shell you do a multi update by passing true as the fourth argument to update(), where the the third argument is the upsert argument: db.test.update({foo: “bar”}, {$set: {test: “success!”}}, false, true); For versions of mongodb 2.2+ you need to … Read more

How to get the entire document HTML as a string?

MS added the outerHTML and innerHTML properties some time ago. According to MDN, outerHTML is supported in Firefox 11, Chrome 0.2, Internet Explorer 4.0, Opera 7, Safari 1.3, Android, Firefox Mobile 11, IE Mobile, Opera Mobile, and Safari Mobile. outerHTML is in the DOM Parsing and Serialization specification. See quirksmode for browser compatibility for what … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)