package pack import ( "bytes" "encoding/xml" "errors" "fmt" "io" "strconv" "strings" ) // Index is what T5DE reads from a product's index.xml, IMVU's product template. Other elements are ignored. type Index struct { Rating string // ProductRating: "GA" (general) or "AP" (adult) Name string // ProductName Gender string // ProductGender TypeID int64 // ProductTypeID, 0 if absent BodyPattern int64 // BodyPatternProductId, 0 if absent Parent int64 // the product it derives from (__DATAIMPORT product:///index.xml), 0 if none } // ParseIndex parses index.xml. func ParseIndex(data []byte) (*Index, error) { d := xml.NewDecoder(bytes.NewReader(data)) d.Strict = false d.Entity = xml.HTMLEntity d.CharsetReader = charsetReader values := map[string]string{} depth := 0 root := false var field string // the top-level element being read, if wanted var text strings.Builder for { tok, err := d.Token() if err == io.EOF { break } if err != nil { return nil, err } switch t := tok.(type) { case xml.StartElement: depth++ if depth == 1 && t.Name.Local != "Template" { return nil, fmt.Errorf("root element is <%s>, not