antchfx / xmlquery

xmlquery is Golang XPath package for XML query.

Home Page:https://github.com/antchfx/xpath

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DTD/DocType gets stripped

Solander opened this issue · comments

I'm trying to update an existing XML by parsing it, finding the correct nodes, update them and writing the code to a new file.
I realized that the DocType gets stripped from the XML which makes it invalid in the program that will use it.
Is there any way around it?

My test code: (Edit: The code lacks proper backticks because GitHub can't escape them apparently.)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Workspace>
<Workspace xmlns="http://www.qlcplus.org/Workspace" CurrentWindow="FixtureManager">
  <Creator>
    <Name>Q Light Controller Plus</Name>
    <Version>4.12.3</Version>
  </Creator>
</Workspace>


doc, err := xmlquery.Parse(strings.NewReader(xmlInput))
if err != nil {
	panic(err)
}

newData := doc.OutputXML(false)
fmt.Println(newData)

Outputs raw:

<?xml version="1.0" encoding="UTF-8"?><Workspace xmlns="http://www.qlcplus.org/Workspace" CurrentWindow="FixtureManager"><Creator><Name>Q Light Controller Plus</Name><Version>4.12.3</Version></Creator></Workspace>

Outputs pretty:

<?xml version="1.0" encoding="UTF-8"?>
<Workspace xmlns="http://www.qlcplus.org/Workspace" CurrentWindow="FixtureManager">
  <Creator>
    <Name>Q Light Controller Plus</Name>
    <Version>4.12.3</Version>
  </Creator>
</Workspace>