A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: XMl Parsing without using Tag Values

  1. #1
    Junior Member
    Join Date
    Aug 2001
    Hi All,
    I have xml file as :

    <CityName> Mumbai </CityName>
    <CityName> Calcutta </CityName>
    <CityName> Chicago </CityName>
    <CityName> NewYork </CityName>
    <CityName> Manhutton </CityName>

    Noe I want to parse this xml file.

    The output I want is something like:

    myArray = ["India","USA"]
    CapitalArray = ["Delhi","Washington"]
    MainCiryNumbers = [2,3]
    MainCitiesName = [["Mumbai","Calcutta"],["Chicago","NewYork","Manhutton"]]

    My main concern is that I dont want to parse the xml file using TAG Values like "Countries" ,"CityName", etc. becz If the client changes XML Tag Name what will happen ?

    So even though I cant get the array structure as above, I have another option :

    MyArray [0] = "Object" which contains all TAgs and their TAg Values about "India"

    MyArray [1] = "Object" which contains all TAgs and their TAg Values about "USA"

    Waiting for ur reply.


  2. #2
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    It would be possible (but more dangerous) to rely on the order of the tags in the XML file.

    The idea, and principal behind XML is to establish a known data format, with specific tags to be included. Then future versions of your software can produce this output and add tags without breaking the original version of the software:


    V1 XML Data File:

    < coolData>
        < Name>
           Billy Bloggs
        < /Name>
    < /coolData>
    Now Version 2 of the software has an address field:

    V2 XML Data File:

    < coolData>
        < Address>
           27 Bloggs St
        < /Address>
        < Name>
           Billy Bloggs
        < /Name>
    < /coolData>
    Now if I parse this version 2 file with an application that parses version 1 files then everything will still work. However if you did as you suggest and check the output by structure rather than tag then you will come unstuck and your names will become addresses.

    What I would suggest is that you and your client agree on an XML DTD. This would force you and them to comply to a specific data setup. If it changes then you will need to recreate there application. However they can extend the dtd and data without breaking your application. That is what the X (extensible) in XML means.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center