2 Replies Latest reply on Nov 14, 2007 2:31 AM by VIJAYPOTHIREDDY

    Performance of Webservices

    VIJAYPOTHIREDDY
      i have a web services that returns the xml data, the size of the repose is 40% less if i used XML Attributes instead of XML Child Elements.

      Response format when i used child elements :

      <?xml version="1.0" encoding="utf-8"?>
      <ArrayOfEvent xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=" http://www.w3.org/2001/XMLSchema" xmlns=" http://tempuri.org/">
      <Event>
      <dDate>1</dDate>
      <EventContent>test</EventContent>
      <CustName>test2</CustName>
      </Event>
      <Event>
      <dDate>2</dDate>
      <EventContent>test</EventContent>
      <CustName>test2</CustName>
      </Event>
      <ArrayOfEvent >

      Response format when i used properties:

      <?xml version="1.0" encoding="utf-8"?>
      <ArrayOfEvent xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=" http://www.w3.org/2001/XMLSchema" xmlns=" http://tempuri.org/">
      <Event dDate="1" EventContent="test" CustName="test2" />
      <Event dDate="2" EventContent="test" CustName="test2" />
      <ArrayOfEvent >

      does flex parse the xml data faster if i used attributes over child elements?
      and also i wanted to know some expert comments,
        • 1. Re: Performance of Webservices
          Haravikk the Horse
          I'd imagine Flex (like most XML parsers) would parse the smaller file faster, since most of them simply read tokens from the stream as they arrive, so the less time it takes to arrive, the quicker it can be parsed into a message.

          As for the XML format, that's up to you. Typically my rule for attributes is that it should really be data used to identify or sort a tag, such as an ID, a timestamp or maybe a name. However, content typically should go inside the tag, or in a child-tag within it.

          So in your case I would probably put your event tag something like:

          <Event dDate="1" CustName="test2">test</Event>

          Or if you think you will have events later that might need more content parts:

          <Event dDate="1" CustName="test2">
          - <EventContent>test</EventContent>
          </Event>

          Both reduce the size a bit by using attributes but should hopefully remain neat enough to be useful. It's very much a case that XML isn't 100% strict on when to use attributes or child-tags, or rather, there are too many cases where it's unclear. So as I say, attributes are usually useful for identifying, sorting or specifying something important (type*). While actual data that won't be used for any of these goes in child-tags.
          * What I mean by 'type' is if you had property called "DataType" that defined the event as being one containing text, or an integer. Then this goes as an attribute since it determines the behaviour when reading the content.

          I hope that's useful, and hopefully some others will comment as well as I'm hardly an expert.

          As an additional note; if your requirements are ONLY performance, then (if you can) you may wish to consider a non-XML format. While XML is great for readability, and Flex has some great tools for working with raw XML strings, it is very wasteful (as you've seen), refer to the document for Sockets in Flex. However, they are much more complex to implement. As noted in another thread I'm trying to port a currently Java-based Binary XML format over to Flex, but I'm very much in research stages, it's a way off yet. However, it basically takes XML tags and turns them into short-hand forms that are quicker to send, and sends certain data-types as raw bytes. It's good as the difference in size due to attributes verus tags is non-existent. But yeah, gonna be a while till I complete it for Flex, and the Java one is not open-source as I may have to change the specification at any time.
          • 2. Re: Performance of Webservices
            VIJAYPOTHIREDDY Level 1
            Thanks for the good answer :)