CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2008
    Posts
    9

    xml to excel (parsing)

    Hi All,
    First of all I would like to thank you for the support. I am new in coding and need assistance in getting a specific xml content to an excel spreadsheet or to a datagridview.

    the XML file is not a standard one (i think and below is a sample).
    what i need from this xml file is the following data:

    the name (Towers xxx] of the alert and the gps points (dont need the utm)

    this is the xml
    Code:
    <?xml version="1.0" encoding="UTF-16"?>
    <layer>
        <name>
            SF Zones
        </name>
        <alert_area_object>
            <creation_time>
                1303889594
            </creation_time>
            <name>
                Tower 1
            </name>
            <description>
                Fence Alert
            </description>
            <event_types num="1">
                <event_type>
                    11111
                </event_type>
            </event_types>
            <event_severity>
                2
            </event_severity>
            <event_override_flag>
                false
            </event_override_flag>
            <identities num="0"/>
            <categories num="0"/>
            <groups num="0"/>
            <target_appear_in_area>
                true
            </target_appear_in_area>
            <target_enter_area>
                true
            </target_enter_area>
            <target_leave_area>
                true
            </target_leave_area>
            <from_hour>
                0
            </from_hour>
            <from_minute>
                0
            </from_minute>
            <to_hour>
                23
            </to_hour>
            <to_minute>
                59
            </to_minute>
            <from_speed>
                0
            </from_speed>
            <to_speed>
                98.8889
            </to_speed>
            <weighting>
                <weight>
                    <type>
                        2
                    </type>
                    <value>
                        99
                    </value>
                </weight>
                <weight>
                    <type>
                        204
                    </type>
                    <value>
                        99
                    </value>
                </weight>
                <weight>
                    <type>
                        205
                    </type>
                    <value>
                        99
                    </value>
                </weight>
            </weighting>
            <visual_feedback>
                true
            </visual_feedback>
            <sound_repeats>
                -1
            </sound_repeats>
            <wave_file>
                C:\4C\RunTime\OWP\Sounds\sirenwawa.wav
            </wave_file>
            <utm_zone>
                40
            </utm_zone>
            <shape type="ClosedPolygon">
                <num_of_alloc_points>
                    22
                </num_of_alloc_points>
                <num_of_points>
                    5
                </num_of_points>
                <geo_position lat="40.76876678920284" long="-73.98097831075269"/>
                <geo_position lat="40.76869191861909" long="-73.98078254132794"/>
                <geo_position lat="40.76839192572469" long="-73.97999998924834"/>
                <geo_position lat="40.76749000414105" long="-73.97804528571041"/>
                <geo_position lat="40.76643902004108" long="-73.97593868227233"/>
                <utm_points x="132131" y="132131"/>
                <utm_points x="132131" y="132131"/>
                <utm_points x="132131" y="132131"/>
                <utm_points x="132131" y="132131"/>
                <utm_points x="132131" y="132131"/>
            </shape>
        </alert_area_object>
        <alert_area_object>
            <creation_time>
                1303890003
            </creation_time>
            <name>
                Towers 1 to 4
            </name>
            <description>
                Fence Alert
            </description>
            <event_types num="1">
                <event_type>
                    11111
                </event_type>
            </event_types>
            <event_severity>
                2
            </event_severity>
            <event_override_flag>
                false
            </event_override_flag>
            <identities num="0"/>
            <categories num="0"/>
            <groups num="0"/>
            <target_appear_in_area>
                true
            </target_appear_in_area>
            <target_enter_area>
                true
            </target_enter_area>
            <target_leave_area>
                true
            </target_leave_area>
            <from_hour>
                0
            </from_hour>
            <from_minute>
                0
            </from_minute>
            <to_hour>
                23
            </to_hour>
            <to_minute>
                59
            </to_minute>
            <from_speed>
                0
            </from_speed>
            <to_speed>
                98.8889
            </to_speed>
            <weighting>
                <weight>
                    <type>
                        2
                    </type>
                    <value>
                        99
                    </value>
                </weight>
                <weight>
                    <type>
                        204
                    </type>
                    <value>
                        99
                    </value>
                </weight>
                <weight>
                    <type>
                        205
                    </type>
                    <value>
                        99
                    </value>
                </weight>
            </weighting>
            <visual_feedback>
                true
            </visual_feedback>
            <sound_repeats>
                -1
            </sound_repeats>
            <wave_file>
                C:\4C\RunTime\OWP\Sounds\sirenwawa.wav
            </wave_file>
            <utm_zone>
                40
            </utm_zone>
            <shape type="ClosedPolygon">
                <num_of_alloc_points>
                    22
                </num_of_alloc_points>
                <num_of_points>
                    6
                </num_of_points>
                <geo_position lat="40.76876678920284" long="-73.98097831075269"/>
                <geo_position lat="40.76869191861909" long="-73.98078254132794"/>
                <geo_position lat="40.76839192572469" long="-73.97999998924834"/>
                <geo_position lat="40.76749000414105" long="-73.97804528571041"/>
                <geo_position lat="40.76643902004108" long="-73.97593868227233"/>
                <utm_points x="132131" y="132131"/>
                <utm_points x="132131" y="132131"/>
                <utm_points x="132131" y="132131"/>
                <utm_points x="132131" y="132131"/>
                <utm_points x="132131" y="132131"/>
            </shape>
        </alert_area_object>
    </layer>
    thanks again

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: xml to excel (parsing)

    You can create a few serialization classes and then use the XmlSerializer.Deserialize method to read the xml.

    See the following post for an example (study the xml attributes to see which apply to your xml schema):
    http://www.codeguru.com/forum/showthread.php?t=498232

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

Featured