| Author |
getting Document fragment as String
|
manuel aldana
Ranch Hand
Joined: Dec 29, 2005
Posts: 308
|
|
hi, i want to get a string from a fragment of Document. something like: public String getStringFromDocumentElement(Element element); param element is a node somewhere in a Document. i thought i could import given element to another document and write it to a StringWriter. or just by passing it as a Node directly to the following: but it does not work. to me it is an obvious functionality to get a document fragment as a String. but i haven't found anything on the net so far. thanks.
|
aldana software engineering blog & .more
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
|
Yes, that is exactly how you do it. Could you give some information beyond "does not work"?
|
 |
manuel aldana
Ranch Hand
Joined: Dec 29, 2005
Posts: 308
|
|
hi, yes you're right it works this way. the error i had, was that a whitespace sneeked in and therefore not an element was printed but a text element. i did check this mistake, because i had a different signature as in my first post and therefore did not get a ClassCastException (passing in a text node instead of element). //NOT receiving ClassCastException passing in text node public String getStringFromElement(Node node){...} //receiving ClassCastException passing in text node public String getStringFromElement(Element element){...}
|
 |
 |
|
|
subject: getting Document fragment as String
|
|
|