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

使用 xsdgen 解组 XML

来源:stackoverflow 2024-04-07 15:09:35 0浏览 收藏

本篇文章主要是结合我之前面试的各种经历和实战开发中遇到的问题解决经验整理的,希望这篇《使用 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基础的同学学习。
    542次学习
  • GO语言核心编程课程
    GO语言核心编程课程
    本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
    511次学习
  • 简单聊聊mysql8与网络通信
    简单聊聊mysql8与网络通信
    如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
    498次学习
  • JavaScript正则表达式基础与实战
    JavaScript正则表达式基础与实战
    在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
    487次学习
  • 从零制作响应式网站—Grid布局
    从零制作响应式网站—Grid布局
    本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
    484次学习
查看更多
AI推荐
  • 千音漫语:智能声音创作助手,AI配音、音视频翻译一站搞定!
    千音漫语
    千音漫语,北京熠声科技倾力打造的智能声音创作助手,提供AI配音、音视频翻译、语音识别、声音克隆等强大功能,助力有声书制作、视频创作、教育培训等领域,官网:https://qianyin123.com
    161次使用
  • MiniWork:智能高效AI工具平台,一站式工作学习效率解决方案
    MiniWork
    MiniWork是一款智能高效的AI工具平台,专为提升工作与学习效率而设计。整合文本处理、图像生成、营销策划及运营管理等多元AI工具,提供精准智能解决方案,让复杂工作简单高效。
    154次使用
  • NoCode (nocode.cn):零代码构建应用、网站、管理系统,降低开发门槛
    NoCode
    NoCode (nocode.cn)是领先的无代码开发平台,通过拖放、AI对话等简单操作,助您快速创建各类应用、网站与管理系统。无需编程知识,轻松实现个人生活、商业经营、企业管理多场景需求,大幅降低开发门槛,高效低成本。
    165次使用
  • 达医智影:阿里巴巴达摩院医疗AI影像早筛平台,CT一扫多筛癌症急慢病
    达医智影
    达医智影,阿里巴巴达摩院医疗AI创新力作。全球率先利用平扫CT实现“一扫多筛”,仅一次CT扫描即可高效识别多种癌症、急症及慢病,为疾病早期发现提供智能、精准的AI影像早筛解决方案。
    163次使用
  • 智慧芽Eureka:更懂技术创新的AI Agent平台,助力研发效率飞跃
    智慧芽Eureka
    智慧芽Eureka,专为技术创新打造的AI Agent平台。深度理解专利、研发、生物医药、材料、科创等复杂场景,通过专家级AI Agent精准执行任务,智能化工作流解放70%生产力,让您专注核心创新。
    171次使用
微信登录更方便
  • 密码登录
  • 注册账号
登录即同意 用户协议隐私政策
返回登录
  • 重置密码