• 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

getting Document fragment as String

 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that is exactly how you do it. Could you give some information beyond "does not work"?
 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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){...}
 
I don't like that guy. The tiny ad agrees with me.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic