0

Lets say we have an XML document that looks like this, which has an unexpected tag <custom1> on <item>

<item>
  <name>...</name>
  <price>...</price>
  <custom1>...</custom1>
</item>

The struct to parse this looks like this

type Item struct {
    Name     string   `xml:"name"`
    Price    string   `xml:"price"`
}

I don't have Custom1 in there since I'm not expecting it. However, is it possible to capture the remaining tags OR the raw representation of the <item> inside the Item struct?

1 Answer 1

2

Use a field with ,innerxml tag:

type Item struct {
    Name  string `xml:"name"`
    Price string `xml:"price"`
    Other string `xml:",innerxml"`
}

Playground: https://play.golang.org/p/Io2CDjSiwx.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.