xrfang / fxml

freestyle xml parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

900 XML/SVG Test cases, one failed

davidrenne opened this issue · comments

I have a file that I ran through the function/example I sent to you on my PR:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 23.0.4, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="24px"
	 height="24px" viewBox="0 0 24 24" enable-background="new 0 0 24 24" xml:space="preserve">
<g id="Bounding_Box">
	<rect fill="none" width="24" height="24"/>
</g>
<g id="Icons">
	<g>
		<g>
			<path d="M2.5,19h19v2h-19V19z M19.34,15.85c0.8,0.21,1.62-0.26,1.84-1.06c0.21-0.8-0.26-1.62-1.06-1.84l-5.31-1.42l-2.76-9.02
				L10.12,2v8.28L5.15,8.95L4.22,6.63L2.77,6.24v5.17L19.34,15.85z"/>
		</g>
	</g>
</g>
</svg>

When it called Encode on it this was the output:

<?xml version="1.0" encoding="UTF-8"?><><><!--Generator: Adobe Illustrator 23.0.4, SVG Export Plug-In . SVG Version: 6.00 Build 0)--></><svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="24px" height="24px" viewBox="0 0 24 24" enable-background="new 0 0 24 24" xml:space="preserve"><g id="Bounding_Box"><rect fill="none" width="24" height="24"></rect></g><g id="Icons"><g><g><path d="M2.5,19h19v2h-19V19z M19.34,15.85c0.8,0.21,1.62-0.26,1.84-1.06c0.21-0.8-0.26-1.62-1.06-1.84l-5.31-1.42l-2.76-9.02&#xA;&#x9;&#x9;&#x9;&#x9;L10.12,2v8.28L5.15,8.95L4.22,6.63L2.77,6.24v5.17L19.34,15.85z" fill="#f44336"></path></g></g></g></svg></>

Notice the <> and the </> are invalid XML. I even just did a Parse and then an Encode and got the same results, so its not my function for WalkMutate at all its a bug elsewhere:

				xt, err := fxml.Parse(f)
				if err != nil {
					return
				}

				var buf2 bytes.Buffer
				err = xt.Encode(&buf2, true)
				if err != nil { 
					return
				}
				xmlString2 := buf2.String()
				session_functions.IsolatedDump(xmlString2)

So as a hack I am just replacing these with nothing and it fixed this one icon until you can get back with me on why you think it's parsing it incorrectly after it encodes it:

				var buf bytes.Buffer
				err = newXML.Encode(&buf, true)
				if err != nil { 
					return
				}
				xmlString := buf.String()
				xmlString = strings.Replace(strings.Replace(xmlString, "</>", "", -1), "<>", "", -1)
				data = []byte(xmlString)

Also if you get a chance, maybe you can help me understand what the purpose of Walk is? I know you can skip nodes or exit during iteration, but if you cant mutate, what is the purpose of the function? My PR #1 keeps it as an isolated function so anyone using the existing can Walk just like normal, but just wanted some background as to why you would walk when there are no return nodes?

As I stated in the document:

Apart from more informative XNodeInfo and better flow control, the most important difference between XWalker and XTraverser is that XWalker works on pointer of XMLTree, i.e. it allows in place modification of the tree nodes.

The purpose of Walk() is to allow in-place modification of the XML node, why do you need a new method WalkMutate()? Could you please use a minimal example to explain? (the SVG example is a bit too complex for the purpose). Thanks

The empty tag bug is fixed, new version v1.2.3 published

I think my Walk function just had logic issues or something because everything in your Walk is mutating things properly on the pointer when I am unit testing a small test case. I'll close #1, you dont need the WalkMutate.