Marshal a xml document with namespace

97 views
Skip to first unread message

jeffreysmith1982

unread,
Jul 31, 2015, 3:12:31 PM7/31/15
to golang-nuts
I'm trying to Marshal the following bit of XML but I'm stumped on how to do it. All I really need to get out of it is all the xs:elements like "<xs:element name="actorID" type="xs:string" minOccurs="1" maxOccurs="1" >"

I have the following struct but I'm assuming I need to declare a namespace of xs but the docs don't give an example of how. Then I would need to use something like schema>element>complextype>sequence>complextype>sequence>element to grab the element I want.

type RequestStruct struct {
XMLName xml.Name `xml:"request"`
}

Can anyone show me how http://play.golang.org/p/L5wBUK2F8u ?

<request signature="1c7f34333d4d-6904c8647b5f-4ec7aee89801-02bc">
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="methodCall">
<xs:complexType>
<xs:sequence>
<xs:element name="SessionState" type="xs:string" minOccurs="0"/>
<xs:element name="trace" type="xs:boolean" minOccurs="0"/>
<xs:element name="params">
<xs:complexType>
<xs:sequence>
<xs:element name="actorID" type="xs:string" minOccurs="1" maxOccurs="1" >
<xs:annotation>
<xs:documentation>
<![CDATA[XX]]>
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="verb" type="xs:string" minOccurs="1" maxOccurs="1" >
<xs:annotation>
<xs:documentation>
<![CDATA[Activity type verb that describes the activity such as post.]]>
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="content" type="xs:string" minOccurs="1" maxOccurs="1" >
<xs:annotation>
<xs:documentation>
<![CDATA[XX]]>
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="extra" type="xs:string" minOccurs="0" >
<xs:annotation>
<xs:documentation>
<![CDATA[XX]]>
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="objectURI" type="xs:string" minOccurs="0" maxOccurs="1" >
<xs:annotation>
<xs:documentation>
<![CDATA[XX]]>
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="activityStreamID" type="xs:string" minOccurs="1" maxOccurs="1" >
<xs:annotation>
<xs:documentation>
<![CDATA[XX]]>
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="title" type="xs:string" minOccurs="0" maxOccurs="1" >
<xs:annotation>
<xs:documentation>
<![CDATA[XX]]>
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="visibility" type="activityVisibilityType" minOccurs="0" default="friend" >
<xs:annotation>
<xs:documentation>
<![CDATA[XX]]>
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="location" type="geoLocationType" minOccurs="0" >
<xs:annotation>
<xs:documentation>
<![CDATA[XX]]>
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="type" type="xs:string" minOccurs="0" >
<xs:annotation>
<xs:documentation>
<![CDATA[XX]]>
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="objectRefUrn" type="xs:anyURI" minOccurs="0" >
<xs:annotation>
<xs:documentation>
<![CDATA[XX]]>
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="activityType" type="activityType" minOccurs="0" >
<xs:annotation>
<xs:documentation>
<![CDATA[XX]]>
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="service" type="xs:string" use="required"/>
<xs:attribute name="method" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
</request>


Giulio Iotti

unread,
Aug 1, 2015, 5:39:47 PM8/1/15
to golang-nuts


On Friday, July 31, 2015 at 10:12:31 PM UTC+3, jeffreysmith1982 wrote:
I'm trying to Marshal the following bit of XML but I'm stumped on how to do it. All I really need to get out of it is all the xs:elements like "<xs:element name="actorID" type="xs:string" minOccurs="1" maxOccurs="1" >"

I have the following struct but I'm assuming I need to declare a namespace of xs but the docs don't give an example of how. Then I would need to use something like schema>element>complextype>sequence>complextype>sequence>element to grab the element I want.

type RequestStruct struct {
XMLName xml.Name `xml:"request"`
}

Can anyone show me how http://play.golang.org/p/L5wBUK2F8u ?

I don't see any problem with your code. The namespace should be handled automatically (or ask here again if it's not).

You are going in the right direction, just finish up the structures that will capture the data you are interested in.


-- 
Giulio
Reply all
Reply to author
Forward
0 new messages