• Post Reply Bookmark Topic Watch Topic
  • New Topic

From String to InputStream required by XML parsers

 
Ian Ferreira
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to Java and came across this problem and is unable to find a example of how to do this.
The Java JAXP parser can take a InputStream as a argument for its parse method. However I have received a String as the XML content to be parsed.
I need to convert the String into a InputStream.
Does anybody have a solution for me please ?
 
Lewin Chan
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
provided you do not care about encoding issues how about
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if encoding might be an issue, you can always force getBytes() to use an encoding that the parser is guaranteed to understand, like UTF-8:
 
Ian Ferreira
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help
I also finaly found a example:-
String stringContext = c_parseSchema + nodeContext;
InputSource input = new InputSource( new StringReader( stringContext ) );
m_domDocument = builder.parse( input );
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!