ShawnMoore / XMLParsing

XMLEncoder & XMLDecoder using the codable protocol in Swift 4.2
MIT License
332 stars 100 forks source link

Encoder: Support for XML namespaces #54

Open mickeyl opened 4 years ago

mickeyl commented 4 years ago

I'd like to use this library for communicating with SOAP web-services. For those, you often encounter namespaces in SOAP requests, e.g.:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://xxxx.com/ipcp/services/v2/common/types" xmlns:par="http://xxxx.com/ipcp/services/v2/reservationWebService/parameters" xmlns:typ1="http://xxxx.com/ipcp/services/v2/reservationWebService/types">
    <soapenv:Header>
        <typ:IpcpHeader>
            <typ:tenantKey>FOO</typ:tenantKey>
            <typ:userName>BAR</typ:userName>
            <typ:password>BAZ</typ:password>
        </typ:IpcpHeader>
    </soapenv:Header>
    <soapenv:Body>
        <par:CreateReservation>
            <par:areaId>302</par:areaId>
            <par:productId>654</par:productId>
            <par:customerId>2852</par:customerId>
            <par:accessInformations>
                <typ:accessTypeId>1</typ:accessTypeId>
                <typ:accessTypeKey></typ:accessTypeKey>
                <typ:accessInformationId></typ:accessInformationId>
                <typ:encodedValue>newnew08234</typ:encodedValue>
                <typ:displayedValue>newnew08234</typ:displayedValue>
            </par:accessInformations>
            <par:accessInformations>
                <typ:accessTypeId>51</typ:accessTypeId>
                <typ:accessInformationId>6004</typ:accessInformationId>
                <typ:encodedValue>830394</typ:encodedValue>
                <typ:displayedValue>830394</typ:displayedValue>
            </par:accessInformations>
            <par:startTime>2019-11-06T12:41:00.000+01:00</par:startTime>
            <par:endTime>2019-12-06T12:41:00.000+01:00</par:endTime>
        </par:CreateReservation>
    </soapenv:Body>
</soapenv:Envelope>

What's the best way to create an XML-document like this one with XMLParsing? It would be nice if we could enhance a struct to feature an optional qualifiedNamespace field that contains the namespace prefix (which would then be automatically inserted by the encoder) and the local name (URI, which could either be automatically scanned and inserted into the envelope, or manually).

MaxDesiatov commented 4 years ago

Hi @mickeyl, thank you for creating this issue. As far as I understand, XMLParsing is no longer maintained. I maintain a fork of this library, it's called XMLCoder and contains bugfixes and feature improvements. One of those is a namespaces flag that you could find helpful. If it doesn't work for your case, please let me know either here, or by opening an issue in the XMLCoder repository, I would be happy to improve the library so that it better serves all users.