The following code works:
String xml = "<object></object>";
HTMLDocument document = new HTMLDocumentImpl();
DocumentFragment doc;
try {
DOMFragmentParser parser = new DOMFragmentParser();
doc = document.createDocumentFragment();
InputSource inputSource = new InputSource( new
ByteArrayInputStream(xml.getBytes()) );
parser.parse(inputSource, doc);
} catch(Exception ex) {
LOGGER.error("failed to parse the xml: " + ex );
return null;
}
On Thu, Aug 18, 2011 at 2:48 PM, Yuhan Zhang <yz...@on...> wrote:
> nvm, my own bad.
>
> Yuhan
>
>
> On Thu, Aug 18, 2011 at 12:50 PM, Yuhan Zhang <yz...@on...>wrote:
>
>> Hi all,
>>
>> I'm having some trouble with parsing html string directly through
>> inputSource.
>> It appears that DOMParser.parse(uri) works properly, but
>> DOMParse.parse(inputSource)
>> always return a DOM element with [#document: null] inside. Can someone
>> take
>> a look on how I did it wrong? thanks!
>>
>> Here is how I did it:
>>
>> DOMParser parser = new DOMParser();
>> InputSource inputSource = new InputSource();
>> inputSource.setCharacterStream(new StringReader(xml));
>> parser.parse(inputSource);
>> doc = parser.getDocument();
>>
>> This doesn' work either:
>>
>> DOMParser parser = new DOMParser();
>> InputSource inputSource = new InputSource( new
>> ByteArrayInputStream(xml.getBytes()) );
>> parser.parse(inputSource);
>> doc = parser.getDocument();
>>
>>
>> Yuhan
>>
>>
>
|