Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
Getting length(no of bytes) of Dom document which is in memory
Aji Ozkan
Ranch Hand
Posts: 98
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi
I am using JDK1.4.
I am constructing a DOM document from scratch .
How can i find the number of bytes of that document
I tried
Documentdoc doc.toString().getBytes().length
this returns 17
also i tried
doc.getDocumentElement().toString().getBytes().length
None of this is working...
How can i get the number of bytes of a DOM document..
Ajit
Thankx
Ajit
Aji Ozkan
Ranch Hand
Posts: 98
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hey
I found out the solution here it goes..
public static String convertNodeToString(Document doc) { try { String nodeString; TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); //transformer.setOutputProperty("omit-xml-declaration", "yes"); StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); DOMSource source = new DOMSource( doc ); transformer.transform( source, result ); nodeString = sw.getBuffer().toString(); System.out.println("Length..."+nodeString.getBytes().length); return nodeString; } catch(Exception e) { e.printStackTrace(); return null; } }
cheers..
Ajit
Thankx
Ajit
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Collaboration
Mark: default encoding for deprecated methods
Converting Document to String
B&S: Invalid Stream Header
Out of Memory error
More...