From d722e2cf7ed3987d868bae36d596b989193fc7a4 Mon Sep 17 00:00:00 2001 From: Jan Bliznicenko Date: Mon, 3 Feb 2025 15:13:51 +0100 Subject: [PATCH 1/3] Fixed direct parsing of files --- src/XML-Parser/XMLDecodingReadStreamAdapter.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/XML-Parser/XMLDecodingReadStreamAdapter.class.st b/src/XML-Parser/XMLDecodingReadStreamAdapter.class.st index aa209feb..5d9bb2da 100644 --- a/src/XML-Parser/XMLDecodingReadStreamAdapter.class.st +++ b/src/XML-Parser/XMLDecodingReadStreamAdapter.class.st @@ -56,7 +56,7 @@ XMLDecodingReadStreamAdapter >> atEnd [ XMLDecodingReadStreamAdapter >> detectEncoding [ prePeekStreamPosition := nil. peekChar := nil. - stream reset. + stream position: 0. (((self hasNullStreamConverter or: [self hasImplicitStreamConverter]) From e833fb0b6cfa9e7443ee64db9e967c55c03a80fa Mon Sep 17 00:00:00 2001 From: Jan Bliznicenko Date: Mon, 3 Feb 2025 17:09:13 +0100 Subject: [PATCH 2/3] Fixed and siplified tree inspection --- src/XML-Parser-Tools/XMLNode.extension.st | 52 ++++++++++------------- src/XML-Parser/XMLNode.class.st | 14 ++++++ 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/XML-Parser-Tools/XMLNode.extension.st b/src/XML-Parser-Tools/XMLNode.extension.st index 19f5a65d..ce354dfe 100644 --- a/src/XML-Parser-Tools/XMLNode.extension.st +++ b/src/XML-Parser-Tools/XMLNode.extension.st @@ -11,22 +11,16 @@ XMLNode >> inspectSourceIn: specBuilder [ { #category : '*XML-Parser-Tools' } XMLNode >> inspectTreeIn: specBuilder [ + - | roots | - roots := self inspectorRoots. ^ specBuilder newTree - roots: roots; - display: [ :aNode | - self inspectorTreeStringFor: aNode - ]; -" displayIcon: [ :aNode | aNode iconName ifNotNil: [ :aName | self iconNamed: aName ] ];" - children: [ :aNode | - - aNode hasChildren ifTrue: [ aNode descendantElements ] ifFalse: [ #() ]] - - + roots: roots; + display: [ :aNode | self inspectorTreeStringFor: aNode ]; + " displayIcon: [ :aNode | aNode iconName ifNotNil: [ :aName | self iconNamed: aName ] ];" + children: [ :aNode | aNode elements ]; + expandRoots ] { #category : '*XML-Parser-Tools' } @@ -37,21 +31,21 @@ XMLNode >> inspectorRoots [ { #category : '*XML-Parser-Tools' } XMLNode >> inspectorTreeStringFor: anXMLElement [ - | display | - anXMLElement isStringNode ifTrue: [ ^ anXMLElement string ]. - display := String streamContents: [:s| - s nextPutAll: anXMLElement name. - anXMLElement hasAttributes ifTrue: [ - s space. - anXMLElement attributes associations do: [:association | - s - nextPutAll: association key; - nextPutAll: '="'; - nextPutAll: association value; - nextPutAll: '"'. - ] separatedBy: [ s space ] - ] - ]. - anXMLElement descendantElements isEmpty ifFalse: [ ^ '<',display, '>' ]. - ^ anXMLElement asString + + anXMLElement hasElements ifFalse: [ ^ anXMLElement asString ]. + ^ String streamContents: [ :s | + s + nextPut: $<; + nextPutAll: anXMLElement name. + anXMLElement hasAttributes ifTrue: [ + s space. + anXMLElement attributes associations + do: [ :association | + s + nextPutAll: association key; + nextPutAll: '="'; + nextPutAll: association value; + nextPutAll: '"' ] + separatedBy: [ s space ] ]. + s nextPut: $> ] ] diff --git a/src/XML-Parser/XMLNode.class.st b/src/XML-Parser/XMLNode.class.st index ac22d42c..b5d3ae47 100644 --- a/src/XML-Parser/XMLNode.class.st +++ b/src/XML-Parser/XMLNode.class.st @@ -183,6 +183,13 @@ XMLNode >> documentRoot [ ^ documentRoot. ] +{ #category : 'accessing' } +XMLNode >> elements [ + "returns a new node list of all of the receiver's elements" + + ^ XMLNodeList empty +] + { #category : 'private' } XMLNode >> errorXMLWritingUnsupported [ XMLDOMException signal: 'The XMLWriter package is required for writng DOM objects' @@ -202,6 +209,13 @@ XMLNode >> hasChildren [ ^ false ] +{ #category : 'testing' } +XMLNode >> hasElements [ + "returns true if the receiver has element children" + + ^ false +] + { #category : 'private' } XMLNode >> hasNodeList: aNodeList [ ^ false From 18090086f0e85232b9c669146227b699426b928f Mon Sep 17 00:00:00 2001 From: Jan Bliznicenko Date: Mon, 3 Feb 2025 17:16:12 +0100 Subject: [PATCH 3/3] Minor tree inspection code cleanup --- src/XML-Parser-Tools/XMLNode.extension.st | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/XML-Parser-Tools/XMLNode.extension.st b/src/XML-Parser-Tools/XMLNode.extension.st index ce354dfe..197ea91e 100644 --- a/src/XML-Parser-Tools/XMLNode.extension.st +++ b/src/XML-Parser-Tools/XMLNode.extension.st @@ -18,7 +18,7 @@ XMLNode >> inspectTreeIn: specBuilder [ ^ specBuilder newTree roots: roots; display: [ :aNode | self inspectorTreeStringFor: aNode ]; - " displayIcon: [ :aNode | aNode iconName ifNotNil: [ :aName | self iconNamed: aName ] ];" + " displayIcon: [ :aNode | aNode iconName ifNotNil: [ :aName | self iconNamed: aName ] ];" children: [ :aNode | aNode elements ]; expandRoots ] @@ -38,14 +38,12 @@ XMLNode >> inspectorTreeStringFor: anXMLElement [ nextPut: $<; nextPutAll: anXMLElement name. anXMLElement hasAttributes ifTrue: [ - s space. - anXMLElement attributes associations - do: [ :association | - s - nextPutAll: association key; - nextPutAll: '="'; - nextPutAll: association value; - nextPutAll: '"' ] - separatedBy: [ s space ] ]. + anXMLElement attributes associations do: [ :association | + s + space; + nextPutAll: association key; + nextPutAll: '="'; + nextPutAll: association value; + nextPutAll: '"' ] ]. s nextPut: $> ] ]