FAQ
Is there a way to use encoding/xml to unmarshal name space information when
it is embedded in an attribute value?

This is used sometimes for describing types, as defined
here: http://www.w3.org/1999/03/31-XMLNamespace-values#Type_Identification

Concretely, I am parsing SOAP WSDLs that encode name space data in embedded
schemas as in the type attributes in this XML:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:pis="urn:provider/interface/service/" xmlns:tns=
"urn:dictionary:com.corp.webservices" xmlns:wsdl=
"http://schemas.xmlsoap.org/wsdl/" xmlns:xsd=
"http://www.w3.org/2001/XMLSchema" name="service" targetNamespace=
"urn:dictionary:com.corp.webservices">
   <wsdl:types>
     <xsd:schema targetNamespace="urn:dictionary:com.corp.webservices">
       <xsd:element name="getPublicDataResponse">
         <xsd:complexType>
           <xsd:sequence>
             <xsd:element name="code" type="xsd:string" minOccurs="1"
maxOccurs="1"/>
             <xsd:element name="data" type="tns:customData" minOccurs="0"
maxOccurs="unbounded"/>
           </xsd:sequence>
         </xsd:complexType>
       </xsd:element>

       <xsd:complexType name="customData">
         <xsd:sequence>
           <xsd:element name="id" type="xsd:string" minOccurs="0" maxOccurs=
"1"/>
         </xsd:sequence>
       </xsd:complexType>
       ...

The type values are "xsd:string" and "tns:customData". The values are
namespaced according to namespaces defined in the document. Although "xsd"
and "tns" are customary they may not be used in other documents so I'm
trying to find a generic solution.

I can unmarshal the values to strings relatively easily, but it looks like
all the namespace information is hidden in the internals of xml.Decoder.

Is there a clever way to do this, or will I need to create an UnmarshalXML
for each element type and keep my own stack of namespaces?

Thanks,
Ian

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Robert Stepanek at Apr 4, 2015 at 6:51 am
    I am not sure if if helps in your particular case, but Roger Peppe has
    improved XML namespace handling in Go's current development version. More
    details here:

    https://go-review.googlesource.com/6927
    https://go-review.googlesource.com/5910
    https://go-review.googlesource.com/2660

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Ian Terrell at Apr 6, 2015 at 6:11 pm
    Thank you for your note. I reviewed those changes and they don't appear to
    help in this case.

    I believe this to be common, so I wonder if this is something the standard
    library should better support?

    To establish the use cases:

        - In SOAP, WSDLs are defined with QNames in attribute values in many
        places, as you can see here: http://www.w3.org/TR/wsdl#_document-s
        - Here's a discussion on the general case in an approved TAG
        finding: http://www.w3.org/2001/tag/doc/qnameids-2004-03-17#sec-qnames-other

    From the last link:
    Other specifications ... have taken QNames and employed them in contexts
    other than element and attribute names. Specifically, QNames have been used
    in attribute values ...
    Here are two ways encoding/xml could approach this issue:

        1. Struct fields of type xml.Name and annotated with ",attr" could be
        marshaled to and unmarshaled from qname values.
        2. xml.Decoder could export the translate
        <http://golang.org/src/encoding/xml/xml.go#L299> method.

    Does anyone have any thoughts support for this making it into the standard
    library, or on a prospective approach?

    Thanks,
    Ian


    On Friday, April 3, 2015 at 11:51:46 PM UTC-7, Robert Stepanek wrote:

    I am not sure if if helps in your particular case, but Roger Peppe has
    improved XML namespace handling in Go's current development version. More
    details here:

    https://go-review.googlesource.com/6927
    https://go-review.googlesource.com/5910
    https://go-review.googlesource.com/2660
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 3, '15 at 11:09p
activeApr 6, '15 at 6:11p
posts3
users2
websitegolang.org

2 users in discussion

Ian Terrell: 2 posts Robert Stepanek: 1 post

People

Translate

site design / logo © 2022 Grokbase