Hi! I want to get the info from a simple XML-file and use it in the system to get strings from each tag. How do I handle that? Many thanks in advance! Marcus
On 11/26/05, Marcus Pedersén marcus.pedersen@comhem.se wrote:
I want to get the info from a simple XML-file and use it in the system to get strings from each tag.
I snipped a method from my SqueakPeople package which I hope serves as illustration (package available on Squeak Source)
Hth,
Cees
fromXml: aByteString | projDir file answer doc info info2 | projDir := (FileDirectory default directoryNamed: 'proj') directoryNamed: aByteString. file := projDir readOnlyFileNamed: 'info.xml'. file ifNil: [^nil]. [answer := self new. doc := XMLDOMParser parseDocumentFrom: file] ensure: [file close].
answer projectName: aByteString. info := doc elementAt: 'info'. info2 := info elementAt: 'info'.
answer creationDate: (info elementAt: 'cdate') contentString; url: (info2 attributeAt: 'url'); squeakMapUrl: (info2 attributeAt: 'smurl'); license: (info2 attributeAt: 'license'); notes: (info2 attributeAt: 'notes'); creator: (info2 attributeAt: 'creator'); locked: (info2 attributeAt: 'locked') = 'yes'.
file := projDir fileNamed: 'staff-name.xml'. file ifNotNil: [ [doc := XMLDOMParser parseDocumentFrom: file. self fillProjectRelationsInNew: answer from: doc] ensure: [file close]].
^answer
squeak-dev@lists.squeakfoundation.org