Skip to content

Instantly share code, notes, and snippets.

@miku

miku/README.md Secret

Last active May 19, 2022 11:20
Show Gist options
  • Save miku/3df6ddbba9f7baf078662d682e8f32e0 to your computer and use it in GitHub Desktop.
Save miku/3df6ddbba9f7baf078662d682e8f32e0 to your computer and use it in GitHub Desktop.

Example for

$ go run main.go < rets.xml | jq .
{
  "XMLName": {
    "Space": "",
    "Local": "RETS"
  },
  "Text": "\n\n",
  "ReplyCode": "0",
  "ReplyText": "Operation successful.",
  "METADATATABLE": {
    "Text": "\n\n\n\n\n\n\n\n\n",
    "Resource": "ActiveAgent",
    "Class": "MEMB",
    "Version": "01.72.10236",
    "Date": "2011-03-03T00:29:23",
    "COLUMNS": {
      "Text": "\tMetadataEntryID\tSystemName\tStandardName\tLongName\tDBName\tShortName\tMaximumLength\tDataType\tPrecision\tSearchable\tInterpretation\tAlignment\tUseSeparator\tEditMaskID\tLookupName\tMaxSelect\tUnits\tIndex\tMinimum\tMaximum\tDefault\tRequired\tSearchHelpID\tUnique\tModTimeStamp\tForeignKeyName\tForeignField\tInKeyindex\t"
    },
    "DATA": [
      {
        "Text": "\t7\tCity\t\tCity\tCity\tCity\t11\tCharacter\t0\t1\t\tLeft\t0\t\t\t0\t\t0\t0\t0\t0\t0\tCity\t0\t0\t1\tMemberNumber\t0\t"
      },
      {
        "Text": "\t9\tContactAddlPhoneType1\t\tContact Additional Phone Type 1\tAddlPhTyp1\tContact Addl Ph Type 1\t1\tCharacter\t0\t1\tLookup\tLeft\t0\t\tContactAddlPhoneType\t0\t\t0\t0\t0\t0\t0\tContactAddlPhoneType\t0\t0\t1\tMemberNumber\t0\t"
      },
      {
        "Text": "\t11\tContactAddlPhoneType2\t\tContact Additional Phone Type 2\tAddlPhTyp2\tContact Addl Ph Type 2\t1\tCharacter\t0\t1\tLookup\tLeft\t0\t\tContactAddlPhoneType\t0\t\t0\t0\t0\t0\t0\tContactAddlPhoneType\t0\t0\t1\tMemberNumber\t0\t"
      },
      {
        "Text": "\t13\tContactAddlPhoneType3\t\tContact Additional Phone Type 3\tAddlPhTyp3\tContact Addl Ph Type 3\t1\tCharacter\t0\t1\tLookup\tLeft\t0\t\tContactAddlPhoneType\t0\t\t0\t0\t0\t0\t0\tContactAddlPhoneType\t0\t0\t1\tMemberNumber\t0\t"
      },
      {
        "Text": "\t15\tContactPhoneAreaCode1\t\tContact Phone Area Code 1\tContPhAC1\tContact Phone AC 1\t3\tCharacter\t0\t1\t\tLeft\t0\t\t\t0\t\t0\t0\t0\t0\t0\tContactPhoneAreaCode\t0\t0\t1\tMemberNumber\t0\t"
      },
      {
        "Text": "\t17\tContactPhoneAreaCode2\t\tContact Phone Area Code 2\tContPhAC2\tContact Phone AC 2\t3\tCharacter\t0\t1\t\tLeft\t0\t\t\t0\t\t0\t0\t0\t0\t0\tContactPhoneAreaCode\t0\t0\t1\tMemberNumber\t0\t"
      },
      {
        "Text": "\t19\tContactPhoneAreaCode3\t\tContact Phone Area Code 3\tContPhAC3\tContact Phone AC 3\t3\tCharacter\t0\t1\t\tLeft\t0\t\t\t0\t\t0\t0\t0\t0\t0\tContactPhoneAreaCode\t0\t0\t1\tMemberNumber\t0\t"
      }
    ]
  }
}
// curl -sL https://git.io/fN4Pq | zek -e -p
package main
import (
"encoding/json"
"encoding/xml"
"fmt"
"log"
"os"
"golang.org/x/net/html/charset"
)
// RETS was generated 2018-07-24 13:16:56 by tir on sol.
type RETS struct {
XMLName xml.Name `xml:"RETS"`
Text string `xml:",chardata"`
ReplyCode string `xml:"ReplyCode,attr"`
ReplyText string `xml:"ReplyText,attr"`
METADATATABLE struct {
Text string `xml:",chardata"`
Resource string `xml:"Resource,attr"`
Class string `xml:"Class,attr"`
Version string `xml:"Version,attr"`
Date string `xml:"Date,attr"`
COLUMNS struct {
Text string `xml:",chardata"` // MetadataEntryID SystemNam...
} `xml:"COLUMNS"`
DATA []struct {
Text string `xml:",chardata"` // 7 City City City City 11...
} `xml:"DATA"`
} `xml:"METADATA-TABLE"`
}
func main() {
dec := xml.NewDecoder(os.Stdin)
dec.CharsetReader = charset.NewReaderLabel
dec.Strict = false
var doc RETS
if err := dec.Decode(&doc); err != nil {
log.Fatal(err)
}
b, err := json.Marshal(doc)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(b))
}
<RETS ReplyCode="0" ReplyText="Operation successful.">
<METADATA-TABLE Resource="ActiveAgent" Class="MEMB" Version="01.72.10236" Date="2011-03-03T00:29:23">
<COLUMNS> MetadataEntryID SystemName StandardName LongName DBName ShortName MaximumLength DataType Precision Searchable Interpretation Alignment UseSeparator EditMaskID LookupName MaxSelect Units Index Minimum Maximum Default Required SearchHelpID Unique ModTimeStamp ForeignKeyName ForeignField InKeyindex </COLUMNS>
<DATA> 7 City City City City 11 Character 0 1 Left 0 0 0 0 0 0 0 City 0 0 1 MemberNumber 0 </DATA>
<DATA> 9 ContactAddlPhoneType1 Contact Additional Phone Type 1 AddlPhTyp1 Contact Addl Ph Type 1 1 Character 0 1 Lookup Left 0 ContactAddlPhoneType 0 0 0 0 0 0 ContactAddlPhoneType 0 0 1 MemberNumber 0 </DATA>
<DATA> 11 ContactAddlPhoneType2 Contact Additional Phone Type 2 AddlPhTyp2 Contact Addl Ph Type 2 1 Character 0 1 Lookup Left 0 ContactAddlPhoneType 0 0 0 0 0 0 ContactAddlPhoneType 0 0 1 MemberNumber 0 </DATA>
<DATA> 13 ContactAddlPhoneType3 Contact Additional Phone Type 3 AddlPhTyp3 Contact Addl Ph Type 3 1 Character 0 1 Lookup Left 0 ContactAddlPhoneType 0 0 0 0 0 0 ContactAddlPhoneType 0 0 1 MemberNumber 0 </DATA>
<DATA> 15 ContactPhoneAreaCode1 Contact Phone Area Code 1 ContPhAC1 Contact Phone AC 1 3 Character 0 1 Left 0 0 0 0 0 0 0 ContactPhoneAreaCode 0 0 1 MemberNumber 0 </DATA>
<DATA> 17 ContactPhoneAreaCode2 Contact Phone Area Code 2 ContPhAC2 Contact Phone AC 2 3 Character 0 1 Left 0 0 0 0 0 0 0 ContactPhoneAreaCode 0 0 1 MemberNumber 0 </DATA>
<DATA> 19 ContactPhoneAreaCode3 Contact Phone Area Code 3 ContPhAC3 Contact Phone AC 3 3 Character 0 1 Left 0 0 0 0 0 0 0 ContactPhoneAreaCode 0 0 1 MemberNumber 0 </DATA>
</METADATA-TABLE>
</RETS>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment