Attribute ordering is insignificant in XML. If you rely on attribute ordering, you're not using XML as specified (see, for instance, http://mail.zope.org/pipermail/zope-dev/2002-May/016341.html). In other words, you cannot count on a spec-compliant library like Xerces to support this behavior. Even if you can make it work somehow for your app, other XML processors can freely rearrange attribute order (indeed, Canonical XML http://www.w3.org/TR/xml-c14n mandates an order similar to what Xerces is doing), so your documents will have extremely limited usefulness. (And it's harder to keep your documents away from other XML processors than you might think. XML processors such as Internet Explorer are pervasive and becoming ever more so.)
Element order, or the other hand, is guaranteed to be preserved. If ordering is important, order elements, not attributes. > -----Original Message----- > From: Ujwala Maheshwari [mailto:[EMAIL PROTECTED] > Sent: Thursday, February 12, 2004 7:15 PM > To: [EMAIL PROTECTED] > Subject: order of attributes ... > > > Hi, > > I am using xerces-c 1.7 API. When I execute the following > lines of code, the order in which I get back the attributes > is sorted alphabetically. Is there a way to get the list of > attributes the way they appeared in my original XML Node? > > DOM_NamedNodeMap attributes = toWrite.getAttributes(); > int attrCount = attributes.getLength(); > for (i = 0; i < attrCount; i++) > { > DOM_Node attribute = attributes.item(i); > DOMString attrNodeName = attribute.getNodeName(); > char * attrValue = attrNodeName.transcode(); > > // print out the attribute value... > // delete the transcoded string... > } > > If my node was as follows: > > <MyNode type="myType" name="myName"> > > I want the attributes.item(0) to be type and > attributes.item(1) to be name but it gives me name first and > type next. > > Thank you in advance for any replies. > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
