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

Processing instructions don't seem to be handled correctly

cideM opened this issue · comments

The snippet below gives me

$ go run main.go

<item><para>first</para><?xe-change-remove-start?><item><para>second</para></item></item>


<?xml version="1.0" encoding="UTF-8"?><list><item><para>first</para><?xe-change-remove-start?><item><para>second</para></item></item></list>

notices that the item nesting is broken. It looks to me as if the input parsing was already broken.

package main

import (
	"fmt"
	"strings"

	"github.com/antchfx/xmlquery"
)

func main() {
	s := `
  <?xml version="1.0" encoding="UTF-8" ?>
  <list>
    <item><para>first</para></item>
    <?xe-change-remove-start?>
    <item><para>second</para></item>
  </list>
  `
	doc, err := xmlquery.Parse(strings.NewReader(s))
	if err != nil {
		panic(err)
	}

	list := xmlquery.FindOne(doc, "//list")

	for c := list.FirstChild; c != nil; c = c.NextSibling {
		fmt.Println(c.OutputXML(true))
	}

	fmt.Println(doc.OutputXMLWithOptions(xmlquery.WithEmptyTagSupport(), xmlquery.WithOutputSelf()))
}