How to make XMLDocument from a string?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to make XMLDocument from a string?

Bob Erb
Is there a way to make an XMLDocument from a string? I want to do
something like this

  XMLDocument new parseDocumentFrom: '<root><child>wah</child></root>'

but #parseDocumentFrom: takes a stream as an argument. I tried
creating a TextStream from the string, then a ReadStream on that, but
that didn't work.

Thanks in advance for any help.

- Bob Erb

Reply | Threaded
Open this post in threaded view
|

Re: How to make XMLDocument from a string?

Zulq Alam
Bob,

I haven't use the XML libraries but I believe you could obtain the
ReadStream from the String by sending #readStream which is understood by
all SequenceableCollection subclasses.

    XMLDOMParser parseDocumentFrom: '<root><child>wah</child></root>'
readStream

You can also construct the ReadStream yourself from the String.

    XMLDOMParser parseDocumentFrom: (ReadStream on:
'<root><child>wah</child></root>')

In my image XMLDocument doesn't understand #parseDocumentFrom do I've
used XMLDOMParser but I'm sure you get the picture.

I think TextStream is used for something completely different and is not
needed here. I hope I've understood your question.

- Zulq.


Bob Erb wrote:
> Is there a way to make an XMLDocument from a string? I want to do
> something like this
>
>   XMLDocument new parseDocumentFrom: '<root><child>wah</child></root>'
>
> but #parseDocumentFrom: takes a stream as an argument.