当前位置:首页 > 文章列表 > Golang > Go问答 > 使用 xsdgen 解组 XML

使用 xsdgen 解组 XML

来源:stackoverflow 2024-04-07 15:09:35 0浏览 收藏
推广推荐
免费电影APP ➜
支持 PC / 移动端,安全直达

本篇文章主要是结合我之前面试的各种经历和实战开发中遇到的问题解决经验整理的,希望这篇《使用 xsdgen 解组 XML》对你有很大帮助!欢迎收藏,分享给更多的需要的朋友学习~

问题内容

我正在尝试使用 golang 解析 xml 文件。

我使用 xsdgen 生成结构部分

我无法使用 xml.unmarshal(bytevalue, &data) 解析文件 我期望程序打印:grandtotalamount.value 这是 671.15,但它打印的是 0。

变量 data 似乎为空,因为这一行没有按我的预期工作: xml.unmarshal(bytevalue, &data)

我没有看到任何编译错误(或者我不知道在哪里可以找到它们)

我觉得我错过了一些东西,你能帮我吗?

xsd 文件:https://gist.github.com/hyperi0n/a5eb805d9f91de84d341ea75cfe6d1bf

xml 文件:

<?xml version='1.0' encoding='utf-8'?>
<rsm:crossindustryinvoice xmlns:qdt="urn:un:unece:uncefact:data:standard:qualifieddatatype:100" xmlns:ram="urn:un:unece:uncefact:data:standard:reusableaggregatebusinessinformationentity:100" xmlns:rsm="urn:un:unece:uncefact:data:standard:crossindustryinvoice:100" xmlns:udt="urn:un:unece:uncefact:data:standard:unqualifieddatatype:100" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">
  <rsm:exchangeddocumentcontext>
    <ram:guidelinespecifieddocumentcontextparameter>
      <ram:id>urn:factur-x.eu:1p0:minimum</ram:id>
    </ram:guidelinespecifieddocumentcontextparameter>
  </rsm:exchangeddocumentcontext>
  <rsm:exchangeddocument>
    <ram:id>fa-2017-0010</ram:id>
    <ram:typecode>380</ram:typecode>
    <ram:issuedatetime>
      <udt:datetimestring format="102">20171113</udt:datetimestring>
    </ram:issuedatetime>
  </rsm:exchangeddocument>
  <rsm:supplychaintradetransaction>
    <ram:applicableheadertradeagreement>
      <ram:sellertradeparty>
        <ram:name>au bon moulin</ram:name>
        <ram:specifiedlegalorganization>
          <ram:id schemeid="0002">99999999800010</ram:id>
        </ram:specifiedlegalorganization>
        <ram:postaltradeaddress>
          <ram:countryid>fr</ram:countryid>
        </ram:postaltradeaddress>
        <ram:specifiedtaxregistration>
          <ram:id schemeid="va">fr11999999998</ram:id>
        </ram:specifiedtaxregistration>
      </ram:sellertradeparty>
      <ram:buyertradeparty>
        <ram:name>ma jolie boutique</ram:name>
        <ram:specifiedlegalorganization>
          <ram:id schemeid="0002">78787878400035</ram:id>
        </ram:specifiedlegalorganization>
        <ram:postaltradeaddress>
          <ram:countryid>fr</ram:countryid>
        </ram:postaltradeaddress>
        <ram:specifiedtaxregistration>
          <ram:id schemeid="va">fr19787878784</ram:id>
        </ram:specifiedtaxregistration>
      </ram:buyertradeparty>
      <ram:buyerorderreferenceddocument>
        <ram:issuerassignedid>po445</ram:issuerassignedid>
      </ram:buyerorderreferenceddocument>
    </ram:applicableheadertradeagreement>
    <ram:applicableheadertradedelivery/>
    <ram:applicableheadertradesettlement>
      <ram:invoicecurrencycode>eur</ram:invoicecurrencycode>
      <ram:specifiedtradesettlementheadermonetarysummation>
        <ram:taxbasistotalamount>624.90</ram:taxbasistotalamount>
        <ram:taxtotalamount currencyid="eur">46.25</ram:taxtotalamount>
        <ram:grandtotalamount>671.15</ram:grandtotalamount>
        <ram:duepayableamount>470.15</ram:duepayableamount>
      </ram:specifiedtradesettlementheadermonetarysummation>
    </ram:applicableheadertradesettlement>
  </rsm:supplychaintradetransaction>
</rsm:crossindustryinvoice>

转到文件:

package main
    
    import (
        "encoding/xml"
        "fmt"
        "io/ioutil"
        "os"
    )
    
    type AmountType struct {
        Value      float64 `xml:",chardata"`
        CurrencyID string  `xml:"currencyID,attr,omitempty"`
    }
    
    // May be one of 1A, AD, AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, AU, AW, AX, AZ, BA, BB, BD, BE, BF, BG, BH, BI, BJ, BL, BM, BN, BO, BQ, BR, BS, BT, BV, BW, BY, BZ, CA, CC, CD, CF, CG, CH, CI, CK, CL, CM, CN, CO, CR, CU, CV, CW, CX, CY, CZ, DE, DJ, DK, DM, DO, DZ, EC, EE, EG, EH, ER, ES, ET, FI, FJ, FK, FM, FO, FR, GA, GB, GD, GE, GF, GG, GH, GI, GL, GM, GN, GP, GQ, GR, GS, GT, GU, GW, GY, HK, HM, HN, HR, HT, HU, ID, IE, IL, IM, IN, IO, IQ, IR, IS, IT, JE, JM, JO, JP, KE, KG, KH, KI, KM, KN, KP, KR, KW, KY, KZ, LA, LB, LC, LI, LK, LR, LS, LT, LU, LV, LY, MA, MC, MD, ME, MF, MG, MH, MK, ML, MM, MN, MO, MP, MQ, MR, MS, MT, MU, MV, MW, MX, MY, MZ, NA, NC, NE, NF, NG, NI, NL, NO, NP, NR, NU, NZ, OM, PA, PE, PF, PG, PH, PK, PL, PM, PN, PR, PS, PT, PW, PY, QA, RE, RO, RS, RU, RW, SA, SB, SC, SD, SE, SG, SH, SI, SJ, SK, SL, SM, SN, SO, SR, SS, ST, SV, SX, SY, SZ, TC, TD, TF, TG, TH, TJ, TK, TL, TM, TN, TO, TR, TT, TV, TW, TZ, UA, UG, UM, US, UY, UZ, VA, VC, VE, VG, VI, VN, VU, WF, WS, YE, YT, ZA, ZM, ZW
    type CountryIDContentType string
    
    type CrossIndustryInvoiceType struct {
        ExchangedDocumentContext    ExchangedDocumentContextType    `xml:"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100 ExchangedDocumentContext"`
        ExchangedDocument           ExchangedDocumentType           `xml:"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100 ExchangedDocument"`
        SupplyChainTradeTransaction SupplyChainTradeTransactionType `xml:"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100 SupplyChainTradeTransaction"`
    }
    
    // May be one of AED, AFN, ALL, AMD, ANG, AOA, ARS, AUD, AWG, AZN, BAM, BBD, BDT, BGN, BHD, BIF, BMD, BND, BOB, BOV, BRL, BSD, BTN, BWP, BYN, BZD, CAD, CDF, CHE, CHF, CHW, CLF, CLP, CNY, COP, COU, CRC, CUC, CUP, CVE, CZK, DJF, DKK, DOP, DZD, EGP, ERN, ETB, EUR, FJD, FKP, GBP, GEL, GHS, GIP, GMD, GNF, GTQ, GYD, HKD, HNL, HRK, HTG, HUF, IDR, ILS, INR, IQD, IRR, ISK, JMD, JOD, JPY, KES, KGS, KHR, KMF, KPW, KRW, KWD, KYD, KZT, LAK, LBP, LKR, LRD, LSL, LYD, MAD, MDL, MGA, MKD, MMK, MNT, MOP, MRU, MUR, MVR, MWK, MXN, MXV, MYR, MZN, NAD, NGN, NIO, NOK, NPR, NZD, OMR, PAB, PEN, PGK, PHP, PKR, PLN, PYG, QAR, RON, RSD, RUB, RWF, SAR, SBD, SCR, SDG, SEK, SGD, SHP, SLL, SOS, SRD, SSP, STN, SVC, SYP, SZL, THB, TJS, TMT, TND, TOP, TRY, TTD, TWD, TZS, UAH, UGX, USD, USN, UYI, UYU, UYW, UZS, VES, VND, VUV, WST, XAF, XAG, XAU, XBA, XBB, XBC, XBD, XCD, XDR, XOF, XPD, XPF, XPT, XSU, XTS, XUA, XXX, YER, ZAR, ZMW, ZWL
    type CurrencyCodeContentType string
    
    type DateTimeString struct {
        Value  string `xml:",chardata"`
        Format string `xml:"format,attr"`
    }
    
    type DateTimeType struct {
        DateTimeString DateTimeString `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 DateTimeString"`
    }
    
    // May be one of 80, 81, 82, 83, 84, 130, 202, 203, 204, 211, 261, 262, 295, 296, 308, 325, 326, 380, 381, 383, 384, 385, 386, 387, 388, 389, 390, 393, 394, 395, 396, 420, 456, 457, 458, 527, 575, 623, 633, 751, 780, 935
    type DocumentCodeContentType string
    
    type DocumentContextParameterType struct {
        ID IDType `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 ID,omitempty"`
    }
    
    type ExchangedDocumentContextType struct {
        BusinessProcessSpecifiedDocumentContextParameter DocumentContextParameterType `xml:"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100 BusinessProcessSpecifiedDocumentContextParameter,omitempty"`
        GuidelineSpecifiedDocumentContextParameter       DocumentContextParameterType `xml:"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100 GuidelineSpecifiedDocumentContextParameter"`
    }
    
    type ExchangedDocumentType struct {
        ID            IDType                  `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 ID"`
        TypeCode      DocumentCodeContentType `xml:"urn:un:unece:uncefact:data:standard:QualifiedDataType:100 TypeCode"`
        IssueDateTime DateTimeType            `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 IssueDateTime"`
    }
    
    type HeaderTradeAgreementType struct {
        BuyerReference               string                 `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 BuyerReference,omitempty"`
        SellerTradeParty             TradePartyType         `xml:"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100 SellerTradeParty"`
        BuyerTradeParty              TradePartyType         `xml:"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100 BuyerTradeParty"`
        BuyerOrderReferencedDocument ReferencedDocumentType `xml:"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100 BuyerOrderReferencedDocument,omitempty"`
    }
    
    type HeaderTradeDeliveryType struct {
    }
    
    type HeaderTradeSettlementType struct {
        InvoiceCurrencyCode                             CurrencyCodeContentType                    `xml:"urn:un:unece:uncefact:data:standard:QualifiedDataType:100 InvoiceCurrencyCode"`
        SpecifiedTradeSettlementHeaderMonetarySummation TradeSettlementHeaderMonetarySummationType `xml:"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100 SpecifiedTradeSettlementHeaderMonetarySummation"`
    }
    
    type IDType struct {
        Value    string `xml:",chardata"`
        SchemeID string `xml:"schemeID,attr,omitempty"`
    }
    
    type LegalOrganizationType struct {
        ID IDType `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 ID,omitempty"`
    }
    
    type ReferencedDocumentType struct {
        IssuerAssignedID IDType `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 IssuerAssignedID"`
    }
    
    type SupplyChainTradeTransactionType struct {
        ApplicableHeaderTradeAgreement  HeaderTradeAgreementType  `xml:"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100 ApplicableHeaderTradeAgreement"`
        ApplicableHeaderTradeDelivery   HeaderTradeDeliveryType   `xml:"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100 ApplicableHeaderTradeDelivery"`
        ApplicableHeaderTradeSettlement HeaderTradeSettlementType `xml:"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100 ApplicableHeaderTradeSettlement"`
    }
    
    type TaxRegistrationType struct {
        ID IDType `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 ID"`
    }
    
    type TradeAddressType struct {
        PostcodeCode           string               `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 PostcodeCode,omitempty"`
        LineOne                string               `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 LineOne,omitempty"`
        LineTwo                string               `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 LineTwo,omitempty"`
        LineThree              string               `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 LineThree,omitempty"`
        CityName               string               `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 CityName,omitempty"`
        CountryID              CountryIDContentType `xml:"urn:un:unece:uncefact:data:standard:QualifiedDataType:100 CountryID"`
        CountrySubDivisionName string               `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 CountrySubDivisionName,omitempty"`
    }
    
    type TradePartyType struct {
        Name                       string                `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 Name"`
        SpecifiedLegalOrganization LegalOrganizationType `xml:"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100 SpecifiedLegalOrganization,omitempty"`
        PostalTradeAddress         TradeAddressType      `xml:"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100 PostalTradeAddress,omitempty"`
        SpecifiedTaxRegistration   []TaxRegistrationType `xml:"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100 SpecifiedTaxRegistration,omitempty"`
    }
    
    type TradeSettlementHeaderMonetarySummationType struct {
        TaxBasisTotalAmount AmountType `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 TaxBasisTotalAmount"`
        TaxTotalAmount      AmountType `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 TaxTotalAmount,omitempty"`
        GrandTotalAmount    AmountType `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 GrandTotalAmount"`
        DuePayableAmount    AmountType `xml:"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100 DuePayableAmount"`
    }
    
    func main() {
    
        xmlFile, err := os.Open("invoice.xml")
        if err != nil {
            fmt.Println(err)
        }
        defer xmlFile.Close()
    
        byteValue, _ := ioutil.ReadAll(xmlFile)
    
        fmt.Println(string(byteValue))
    
        var data CrossIndustryInvoiceType

        xml.Unmarshal(byteValue, &data)
        
fmt.Println(data.SupplyChainTradeTransaction.ApplicableHeaderTradeSettlement.SpecifiedTradeSettlementHeaderMonetarySummation.GrandTotalAmount.Value)
    }

解决方案


我认为这与 Go Issue #13400 有关。命名空间前缀似乎存在问题。事实上,您可以在解组时忽略结构标记中的前缀。

以下代码应该适合您:

package main

import (
    "encoding/xml"
    "fmt"
    "io/ioutil"
    "log"
    "os"
)

type amounttype struct {
    value      float64 `xml:",chardata"`
    currencyid string  `xml:"currencyid,attr,omitempty"`
}

// may be one of 1a, ad, ae, af, ag, ai, al, am, ao, aq, ar, as, at, au, aw, ax, az, ba, bb, bd, be, bf, bg, bh, bi, bj, bl, bm, bn, bo, bq, br, bs, bt, bv, bw, by, bz, ca, cc, cd, cf, cg, ch, ci, ck, cl, cm, cn, co, cr, cu, cv, cw, cx, cy, cz, de, dj, dk, dm, do, dz, ec, ee, eg, eh, er, es, et, fi, fj, fk, fm, fo, fr, ga, gb, gd, ge, gf, gg, gh, gi, gl, gm, gn, gp, gq, gr, gs, gt, gu, gw, gy, hk, hm, hn, hr, ht, hu, id, ie, il, im, in, io, iq, ir, is, it, je, jm, jo, jp, ke, kg, kh, ki, km, kn, kp, kr, kw, ky, kz, la, lb, lc, li, lk, lr, ls, lt, lu, lv, ly, ma, mc, md, me, mf, mg, mh, mk, ml, mm, mn, mo, mp, mq, mr, ms, mt, mu, mv, mw, mx, my, mz, na, nc, ne, nf, ng, ni, nl, no, np, nr, nu, nz, om, pa, pe, pf, pg, ph, pk, pl, pm, pn, pr, ps, pt, pw, py, qa, re, ro, rs, ru, rw, sa, sb, sc, sd, se, sg, sh, si, sj, sk, sl, sm, sn, so, sr, ss, st, sv, sx, sy, sz, tc, td, tf, tg, th, tj, tk, tl, tm, tn, to, tr, tt, tv, tw, tz, ua, ug, um, us, uy, uz, va, vc, ve, vg, vi, vn, vu, wf, ws, ye, yt, za, zm, zw
type countryidcontenttype string

type crossindustryinvoicetype struct {
    exchangeddocumentcontext    exchangeddocumentcontexttype    `xml:"exchangeddocumentcontext"`
    exchangeddocument           exchangeddocumenttype           `xml:"exchangeddocument"`
    supplychaintradetransaction supplychaintradetransactiontype `xml:"supplychaintradetransaction"`
}

// may be one of aed, afn, all, amd, ang, aoa, ars, aud, awg, azn, bam, bbd, bdt, bgn, bhd, bif, bmd, bnd, bob, bov, brl, bsd, btn, bwp, byn, bzd, cad, cdf, che, chf, chw, clf, clp, cny, cop, cou, crc, cuc, cup, cve, czk, djf, dkk, dop, dzd, egp, ern, etb, eur, fjd, fkp, gbp, gel, ghs, gip, gmd, gnf, gtq, gyd, hkd, hnl, hrk, htg, huf, idr, ils, inr, iqd, irr, isk, jmd, jod, jpy, kes, kgs, khr, kmf, kpw, krw, kwd, kyd, kzt, lak, lbp, lkr, lrd, lsl, lyd, mad, mdl, mga, mkd, mmk, mnt, mop, mru, mur, mvr, mwk, mxn, mxv, myr, mzn, nad, ngn, nio, nok, npr, nzd, omr, pab, pen, pgk, php, pkr, pln, pyg, qar, ron, rsd, rub, rwf, sar, sbd, scr, sdg, sek, sgd, shp, sll, sos, srd, ssp, stn, svc, syp, szl, thb, tjs, tmt, tnd, top, try, ttd, twd, tzs, uah, ugx, usd, usn, uyi, uyu, uyw, uzs, ves, vnd, vuv, wst, xaf, xag, xau, xba, xbb, xbc, xbd, xcd, xdr, xof, xpd, xpf, xpt, xsu, xts, xua, xxx, yer, zar, zmw, zwl
type currencycodecontenttype string

type datetimestring struct {
    value  string `xml:",chardata"`
    format string `xml:"format,attr"`
}

type datetimetype struct {
    datetimestring datetimestring `xml:"datetimestring"`
}

// may be one of 80, 81, 82, 83, 84, 130, 202, 203, 204, 211, 261, 262, 295, 296, 308, 325, 326, 380, 381, 383, 384, 385, 386, 387, 388, 389, 390, 393, 394, 395, 396, 420, 456, 457, 458, 527, 575, 623, 633, 751, 780, 935
type documentcodecontenttype string

type documentcontextparametertype struct {
    id idtype `xml:"id,omitempty"`
}

type exchangeddocumentcontexttype struct {
    businessprocessspecifieddocumentcontextparameter documentcontextparametertype `xml:"businessprocessspecifieddocumentcontextparameter,omitempty"`
    guidelinespecifieddocumentcontextparameter       documentcontextparametertype `xml:"guidelinespecifieddocumentcontextparameter"`
}

type exchangeddocumenttype struct {
    id            idtype                  `xml:"id"`
    typecode      documentcodecontenttype `xml:"typecode"`
    issuedatetime datetimetype            `xml:"issuedatetime"`
}

type headertradeagreementtype struct {
    buyerreference               string                 `xml:"buyerreference,omitempty"`
    sellertradeparty             tradepartytype         `xml:"sellertradeparty"`
    buyertradeparty              tradepartytype         `xml:"buyertradeparty"`
    buyerorderreferenceddocument referenceddocumenttype `xml:"buyerorderreferenceddocument,omitempty"`
}

type headertradedeliverytype struct {
}

type headertradesettlementtype struct {
    invoicecurrencycode                             currencycodecontenttype                    `xml:"invoicecurrencycode"`
    specifiedtradesettlementheadermonetarysummation tradesettlementheadermonetarysummationtype `xml:"specifiedtradesettlementheadermonetarysummation"`
}

type idtype struct {
    value    string `xml:",chardata"`
    schemeid string `xml:"schemeid,attr,omitempty"`
}

type legalorganizationtype struct {
    id idtype `xml:"id,omitempty"`
}

type referenceddocumenttype struct {
    issuerassignedid idtype `xml:"issuerassignedid"`
}

type supplychaintradetransactiontype struct {
    applicableheadertradeagreement  headertradeagreementtype  `xml:"applicableheadertradeagreement"`
    applicableheadertradedelivery   headertradedeliverytype   `xml:"applicableheadertradedelivery"`
    applicableheadertradesettlement headertradesettlementtype `xml:"applicableheadertradesettlement"`
}

type taxregistrationtype struct {
    id idtype `xml:"id"`
}

type tradeaddresstype struct {
    postcodecode           string               `xml:"postcodecode,omitempty"`
    lineone                string               `xml:"lineone,omitempty"`
    linetwo                string               `xml:"linetwo,omitempty"`
    linethree              string               `xml:"linethree,omitempty"`
    cityname               string               `xml:"cityname,omitempty"`
    countryid              countryidcontenttype `xml:"countryid"`
    countrysubdivisionname string               `xml:"countrysubdivisionname,omitempty"`
}

type tradepartytype struct {
    name                       string                `xml:"name"`
    specifiedlegalorganization legalorganizationtype `xml:"specifiedlegalorganization,omitempty"`
    postaltradeaddress         tradeaddresstype      `xml:"postaltradeaddress,omitempty"`
    specifiedtaxregistration   []taxregistrationtype `xml:"specifiedtaxregistration,omitempty"`
}

type tradesettlementheadermonetarysummationtype struct {
    taxbasistotalamount amounttype `xml:"taxbasistotalamount"`
    taxtotalamount      amounttype `xml:"taxtotalamount,omitempty"`
    grandtotalamount    amounttype `xml:"grandtotalamount"`
    duepayableamount    amounttype `xml:"duepayableamount"`
}

func main() {
    xmlfile, err := os.open("invoice.xml")
    if err != nil {
        log.fatalln(err)
    }

    byted, err := ioutil.readall(xmlfile)
    if err != nil {
        log.fatalln(err)
    }
    xmlfile.close()

    var data crossindustryinvoicetype
    if err := xml.unmarshal(byted, &data); err != nil {
        log.fatalln(err)
    }

    fmt.printf("%v\n", data.supplychaintradetransaction.applicableheadertradesettlement.specifiedtradesettlementheadermonetarysummation.grandtotalamount.value)
}

输出:

671.15

当我使用xsdgen生成iso20022的相关go代码时,我遇到了同样的问题。应该是xsdgen包里面的一些事情。我已阅读有关 xsdgen 配置的所有选项,但没有选项可以忽略使用 xmltag 添加命名空间。

您可能会专注于 xsdgen 包的实现,或者只是在生成的代码的基础上手动省略额外的命名空间。

本篇关于《使用 xsdgen 解组 XML》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于Golang的相关知识,请关注golang学习网公众号!

版本声明
本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
模拟外部库进行单元测试模拟外部库进行单元测试
上一篇
模拟外部库进行单元测试
理解 Go 语言中空白标识符的奥妙
下一篇
理解 Go 语言中空白标识符的奥妙
查看更多
最新文章
查看更多
课程推荐
  • 前端进阶之JavaScript设计模式
    前端进阶之JavaScript设计模式
    设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
    543次学习
  • GO语言核心编程课程
    GO语言核心编程课程
    本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
    516次学习
  • 简单聊聊mysql8与网络通信
    简单聊聊mysql8与网络通信
    如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
    500次学习
  • JavaScript正则表达式基础与实战
    JavaScript正则表达式基础与实战
    在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
    487次学习
  • 从零制作响应式网站—Grid布局
    从零制作响应式网站—Grid布局
    本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
    485次学习
查看更多
AI推荐
  • ChatExcel酷表:告别Excel难题,北大团队AI助手助您轻松处理数据
    ChatExcel酷表
    ChatExcel酷表是由北京大学团队打造的Excel聊天机器人,用自然语言操控表格,简化数据处理,告别繁琐操作,提升工作效率!适用于学生、上班族及政府人员。
    3207次使用
  • Any绘本:开源免费AI绘本创作工具深度解析
    Any绘本
    探索Any绘本(anypicturebook.com/zh),一款开源免费的AI绘本创作工具,基于Google Gemini与Flux AI模型,让您轻松创作个性化绘本。适用于家庭、教育、创作等多种场景,零门槛,高自由度,技术透明,本地可控。
    3421次使用
  • 可赞AI:AI驱动办公可视化智能工具,一键高效生成文档图表脑图
    可赞AI
    可赞AI,AI驱动的办公可视化智能工具,助您轻松实现文本与可视化元素高效转化。无论是智能文档生成、多格式文本解析,还是一键生成专业图表、脑图、知识卡片,可赞AI都能让信息处理更清晰高效。覆盖数据汇报、会议纪要、内容营销等全场景,大幅提升办公效率,降低专业门槛,是您提升工作效率的得力助手。
    3450次使用
  • 星月写作:AI网文创作神器,助力爆款小说速成
    星月写作
    星月写作是国内首款聚焦中文网络小说创作的AI辅助工具,解决网文作者从构思到变现的全流程痛点。AI扫榜、专属模板、全链路适配,助力新人快速上手,资深作者效率倍增。
    4558次使用
  • MagicLight.ai:叙事驱动AI动画视频创作平台 | 高效生成专业级故事动画
    MagicLight
    MagicLight.ai是全球首款叙事驱动型AI动画视频创作平台,专注于解决从故事想法到完整动画的全流程痛点。它通过自研AI模型,保障角色、风格、场景高度一致性,让零动画经验者也能高效产出专业级叙事内容。广泛适用于独立创作者、动画工作室、教育机构及企业营销,助您轻松实现创意落地与商业化。
    3828次使用
微信登录更方便
  • 密码登录
  • 注册账号
登录即同意 用户协议隐私政策
返回登录
  • 重置密码