XML : Reading type`s property XMLName attribute value

Im working on my own MarshalXML function to get required output format for an input object, but cant seem to find a proper way of giving tags a proper names.

Let say i have:

  type RootElement struct{  XMLName xml.Name `xml:"hello"`  world ChildElement `xml:"world"`  }    

And a child element:

  type ChildElement struct{  Value string  }    

Then Encode method in MarshalXML for RootElement would give me:

  <RootElement>  <ChildElement>  ...  </ChildElement>  </RootElement>    

Instead of that id have to create my own callset of EncodeToken methods in order to put there proper tag names, but even here i have to specify xml.Name as a constant string value even though i already have it defined in the model structs.

Is there some way to get 'hello' and 'world' tag names inside XMLMarshal?

No comments:

Post a Comment