help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] Help with reading/parsing an XML file in GST 3.2


From: Rick Flower
Subject: [Help-smalltalk] Help with reading/parsing an XML file in GST 3.2
Date: Wed, 05 Sep 2012 07:11:41 -0700
User-agent: Apple Webmail/0.6

So.. I was pestering Paolo via email about help with reading small XML
files and parsing them.. Below are his suggestions -- mind you the files to
be parsed are WELL under 1Kb if it matters.

You can create a FilePath object (you will actually get a File) using
#asFile.

So, something like this should work:

content := 'foo.xml' asFile contents.
parser := XML.XMLParser new.
parser validate: false.
parser processDocumentString: content

I don't have the source at hand, but it's better if you avoid reading
the whole contents and instead use a Stream. It should be something
like this:

stream := 'foo.xml' asFile readStream.
parser := XML.XMLParser new.
parser validate: false.
parser processDocumentStream: stream

I've been able to verify that I can do this without issue:

 stream := './path-to/foo.xml' asFile readStream.
 Transcript show: stream.

but when I add the last few lines and have this code snippet it fails :

 stream := './path-to/foo.xml' asFile readStream.

 parser := XML.XMLParser new.
 parser validate: false.
 parser processDocumentStream: stream.

Recompiling classes...
Recompiling class: XML.Attribute
Recompiling selector: #key
Recompiling selector: #value
Recompiling selector: #value:
Recompiling selector: #printOn:
Recompiling selector: #printCanonicalOn:
Recompiling selector: #simpleDescription
Recompiling selector: #isAttribute
Recompiling selector: #isLike:
Recompiling selector: #tag:
Recompiling selector: #tag
Recompiling selector: #expandedName
Recompiling selector: #characterData
Recompiling selector: #name:value:
Recompiling class: XML.Attribute class
Recompiling selector: #name:value:
Object: XMLParser new "" error: did not understand #processDocumentStream:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
XML.XMLParser(Object)>>doesNotUnderstand: #processDocumentStream:
(SysExcept.st:1436)
UndefinedObject>>executeStatements (../../../eps_fltinfra/sdfhelper.st:37)

So, I did a quick search through the XML package (~/packages/xml/...) for
processDocumentStream but found nothing..

Am I missing something? If someone could point me in the right direction,
that would be great..

--Rick



reply via email to

[Prev in Thread] Current Thread [Next in Thread]