On Fri, Jul 22, 2011 at 2:18 PM, Garry Bettle <garry.bet...@gmail.com>wrote:
> Howdy all, > > Hope this message finds everyone well - roll on the weekend! > > I'm trying some calls to an wsdl API I've subscribed to. > > But I'm struggling to know what they want when sending an unsignedByte in a > request. > > I'm using xml.dom.minidom so to start with I have: > from xml.dom.minidom import Document, parseString > import httplib, urlparse > > And later on I create a doc with: > doc=Document() > > And I have a using a little helper to add a text element: > def add_text_element(doc, parent, name, value): > element=doc.createElement(name) > element.appendChild(doc.createTextNode(str(value))) > parent.appendChild(element) > > Should I have a separate class for an unsignedByte? i.e. def > add_byte_element > > What should it look like? > > This is what their API helpdesk have said: > > "In this instance, the PriceFormat is defined as an unsignedByte. > > > > *<xs:complexType name="GetOddsLadderRequest">* > > *<xs:attribute name="PriceFormat" type="xs:unsignedByte" /> * > > *</xs:complexType>*" > > Many thanks! > > Cheers, > > Garry > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > this, *type=**xs:**unsignedByte*, is an attribute. I'm assuming "doc" above is an instance of class Document, so you can get the element by using doc.getElementsByTagName('complexType') or whatever it is you are talking about for the element. That will return an Element instance, and from there you can go haywire adding attributes. The Element class has a method called "setAttribute('string')". You would do this right here: element=doc.createElement(name) <-- wave <--- element.setAttribute('string') <-- your argument here element.appendChild(doc.createTextNode(str(value))) parent.appendChild(element) The node from your example has two attributes, and not one. I'm not sure how important this is for you. Anyway, that's my answer. I'm a newb though, and even more of a newb with XML.
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor