Pure Go implementation of cXML (Commerce XML) with zero external runtime dependencies.
- Parse and serialize cXML using the standard library
encoding/xml - Build outbound cXML documents with fluent builders
- Route inbound payloads to pluggable handlers by payload type
- Shared-secret authentication support
- Optional DTD validation and document registry hooks
This module is:
github.com/Depth8064/go-cxml
For the simple serialize/deserialize entry point, prefer importing the module root:
github.com/Depth8064/go-cxml
Granular packages remain available under:
github.com/Depth8064/go-cxml/cxml/...
Example:
import (
"github.com/Depth8064/go-cxml"
"github.com/Depth8064/go-cxml/cxml/model"
)go get github.com/Depth8064/go-cxmlpackage main
import (
"fmt"
gcxml "github.com/Depth8064/go-cxml"
"github.com/Depth8064/go-cxml/cxml/model"
)
func main() {
ep := gcxml.NewEndpoint()
doc := &model.CXML{
PayloadID: "example-1",
Version: "1.2.014",
Request: &model.Request{OrderRequest: &model.OrderRequest{}},
}
out, err := ep.Serialize(doc)
if err != nil {
panic(err)
}
parsed, err := ep.Deserialize(out)
if err != nil {
panic(err)
}
fmt.Println(parsed.PayloadID)
}The full-pipeline endpoint in cxml/endpoint runs:
- Validate input (DTD)
- Deserialize XML into model
- Authenticate sender credentials
- Route payload to registered handler
- Serialize response cXML
Use cxml/endpoint when receiving inbound cXML. Use the module root package when you only need simple serialization.
This is a breaking cleanup: the old entry-point import path github.com/Depth8064/go-cxml/cxml has been removed. Import github.com/Depth8064/go-cxml instead.
package main
import (
"fmt"
"github.com/Depth8064/go-cxml/cxml/builder"
"github.com/Depth8064/go-cxml/cxml/credential"
"github.com/Depth8064/go-cxml/cxml/endpoint"
"github.com/Depth8064/go-cxml/cxml/handler"
"github.com/Depth8064/go-cxml/cxml/model"
"github.com/Depth8064/go-cxml/cxml/processor"
)
type orderHandler struct{}
func (h *orderHandler) Handle(doc *model.CXML) (*model.CXML, error) {
// Business logic here.
return builder.New().
PayloadID(doc.PayloadID + "-resp").
Version("1.2.069").
Response(&model.Response{Status: &model.Status{Code: "200", Text: "OK"}}).
Build(), nil
}
func main() {
reg := handler.NewRegistry()
reg.Register("OrderRequest", &orderHandler{})
proc := processor.NewProcessor(reg)
creds := credential.NewRegistry([]credential.Entry{
{Domain: "NetworkID", Identity: "buyer", SharedSecret: "secret"},
})
ep := endpoint.NewEndpoint(proc, nil, creds)
// Receive inbound cXML bytes (from HTTP POST body, etc.)
var inboundXML []byte // populate from request
outXML, err := ep.Process(inboundXML)
if err != nil {
panic(err)
}
fmt.Printf("response: %s\n", outXML)
}Use the typed builders in cxml/builder to construct outbound documents:
doc := builder.NewConfirmationRequestBuilder().
PayloadID("conf-001").
Version("1.2.069").
From(&model.Party{Identity: "supplier"}).
To(&model.Party{Identity: "buyer"}).
Sender(&model.Sender{UserAgent: "my-system"}).
Request(&model.ConfirmationRequest{
ConfirmationHeader: &model.ConfirmationHeader{
ConfirmID: "CONF-001",
Operation: "accept",
},
OrderReference: &model.OrderReference{OrderID: "PO-100"},
}).
Build()Available builders:
| Builder | Payload type |
|---|---|
NewOrderRequestBuilder |
OrderRequest |
NewOrderChangeBuilder |
OrderChangeRequest |
NewConfirmationRequestBuilder |
ConfirmationRequest |
NewPunchOutSetupBuilder |
PunchOutSetupRequest |
NewStatusUpdateBuilder |
StatusUpdateRequest |
NewProfileRequestBuilder |
ProfileRequest |
NewReceivingAdviceBuilder |
ReceivingAdviceRequest |
NewShipNoticeBuilder |
ShipNoticeRequest |
NewInvoiceDetailBuilder |
InvoiceDetailRequest |
go test ./cxml/...
go test ./cxml/... -coverprofile=coverage
go tool cover -func=coverage
go vet ./cxml/...cxml/endpoint: orchestration entry point for processingcxml/model: cXML data model typescxml/builder: fluent builders for outbound cXMLcxml/serializer: XML marshal/unmarshal helperscxml/processor: payload-to-handler routingcxml/handler: handler interfaces and registrycxml/auth: authentication interfaces and implementationcxml/credential: credential repository interfaces/registrycxml/validation: DTD validationcxml/document: document registry interfaces/implementation
- Language: Go 1.25+
- Runtime dependencies: none (standard library only)
For vulnerability reporting instructions, see SECURITY.md.
Please read CONTRIBUTING.md before opening a pull request.
This project is licensed under the MIT License. See LICENSE.