[Pharo-project] possible XML enh
Hi I was browsing fixes in squeak and I saw http://code.google.com/p/pharo/issues/detail?id=2822 May be this can help to improve the XML package. Stef Fix printing of XMLElements; add tests for behavior. =============== Diff against XML-Parser-mtf.30 =============== Item was added: + ----- Method: XMLParserTest>>testPrintElements (in category 'tests') ----- + testPrintElements + | node | + node:= (XMLElement new) name: 'foo'; + setAttributes: (Dictionary new); + yourself. + self assert: node asString withBlanksTrimmed = '<foo/>'. + + node:= (XMLElement new) name: 'foo'; + setAttributes: (Dictionary newFromPairs: {'id'. '123'}); + yourself. + self assert: node asString withBlanksTrimmed = '<foo id="123"/>'. + + node:= (XMLElement new) name: 'foo'; + addContent: (XMLStringNode string: 'Hello World'); + setAttributes: (Dictionary new); + yourself. + self assert: node asString withBlanksTrimmed = '<foo>Hello World</foo>'. + + node:= (XMLElement new) name: 'foo'; + addContent: (XMLStringNode string: 'Hello World'); + setAttributes: (Dictionary newFromPairs: {'id'. '123'}); + yourself. + self assert: node asString withBlanksTrimmed = '<foo id="123">Hello World</foo>'. + + ! Item was changed: ----- Method: XMLElement>>isEmpty (in category 'testing') ----- isEmpty + "Answer true if the receiver is empty" + + ^self elementsAndContents isEmpty! - ^self elements isEmpty! Item was changed: ----- Method: XMLElement>>printXMLOn: (in category 'printing') ----- printXMLOn: writer + "Print the receiver in XML form" + writer startElement: self name attributeList: self attributes. (writer canonical not + and: [self isEmpty]) - and: [self isEmpty and: [self attributes isEmpty not]]) ifTrue: [writer endEmptyTag: self name] ifFalse: [ writer endTag. self elementsAndContentsDo: [:content | content printXMLOn: writer]. writer endTag: self name]!
I will look at them this week end. I have a major deadline on Friday Cheers, Alexandre On 17 Aug 2010, at 12:34, Stéphane Ducasse wrote:
Hi
I was browsing fixes in squeak and I saw http://code.google.com/p/pharo/issues/detail?id=2822 May be this can help to improve the XML package.
Stef
Fix printing of XMLElements; add tests for behavior.
=============== Diff against XML-Parser-mtf.30 ===============
Item was added: + ----- Method: XMLParserTest>>testPrintElements (in category 'tests') ----- + testPrintElements + | node | + node:= (XMLElement new) name: 'foo'; + setAttributes: (Dictionary new); + yourself. + self assert: node asString withBlanksTrimmed = '<foo/>'. + + node:= (XMLElement new) name: 'foo'; + setAttributes: (Dictionary newFromPairs: {'id'. '123'}); + yourself. + self assert: node asString withBlanksTrimmed = '<foo id="123"/>'. + + node:= (XMLElement new) name: 'foo'; + addContent: (XMLStringNode string: 'Hello World'); + setAttributes: (Dictionary new); + yourself. + self assert: node asString withBlanksTrimmed = '<foo>Hello World</foo>'. + + node:= (XMLElement new) name: 'foo'; + addContent: (XMLStringNode string: 'Hello World'); + setAttributes: (Dictionary newFromPairs: {'id'. '123'}); + yourself. + self assert: node asString withBlanksTrimmed = '<foo id="123">Hello World</foo>'. + + !
Item was changed: ----- Method: XMLElement>>isEmpty (in category 'testing') ----- isEmpty + "Answer true if the receiver is empty" + + ^self elementsAndContents isEmpty! - ^self elements isEmpty!
Item was changed: ----- Method: XMLElement>>printXMLOn: (in category 'printing') ----- printXMLOn: writer + "Print the receiver in XML form" + writer startElement: self name attributeList: self attributes. (writer canonical not + and: [self isEmpty]) - and: [self isEmpty and: [self attributes isEmpty not]]) ifTrue: [writer endEmptyTag: self name] ifFalse: [ writer endTag. self elementsAndContentsDo: [:content | content printXMLOn: writer]. writer endTag: self name]!
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
participants (2)
-
Alexandre Bergel -
Stéphane Ducasse