C# 如何从kml文件中读取特定值并在c中进行设置

C# 如何从kml文件中读取特定值并在c中进行设置,c#,xml,kml,C#,Xml,Kml,我试图将kml文件中的纬度和经度设置为变量,以供以后使用。我是c语言的新手,到目前为止只能阅读整个文件 我使用Excel将kml文件装箱,并通过网站运行该文件 <?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net

我试图将kml文件中的纬度和经度设置为变量,以供以后使用。我是c语言的新手,到目前为止只能阅读整个文件

我使用Excel将kml文件装箱,并通过网站运行该文件

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
    <name>Earth Point Excel To KML</name>
    <open>1</open>
    <Snippet maxLines="1">Unity_walk_through.xlsx</Snippet>
    <description><![CDATA[Source: Unity_walk_through.xlsx<br/>DateTime: 2013-08-18 11:23:42 UTC<br/><br/>&copy;2013 Earth Point<br/><a target='_blank' href='http://www.earthpoint.us'>www.earthpoint.us</a><br/><br/>For illustration only.&nbsp; User to verify all information.]]></description>
    <Style>
        <IconStyle>
            <Icon>
            </Icon>
        </IconStyle>
        <BalloonStyle>
            <text>$[description]</text>
            <textColor>ff000000</textColor>
            <displayMode>default</displayMode>
        </BalloonStyle>
    </Style>
    <Style id="NormalSheet1Map1">
        <IconStyle>
            <Icon>
                <href>http://www.earthpoint.us/Dots/GoogleEarth/paddle/ltblu-diamond.png</href>
            </Icon>
        </IconStyle>
        <LabelStyle>
        </LabelStyle>
        <BalloonStyle>
            <text>$[description]</text>
        </BalloonStyle>
        <LineStyle>
            <color>ffff00ff</color>
            <width>2</width>
        </LineStyle>
        <PolyStyle>
            <color>00ff00ff</color>
            <fill>0</fill>
        </PolyStyle>
    </Style>
    <StyleMap id="Sheet1Map1">
        <Pair>
            <key>normal</key>
            <styleUrl>#NormalSheet1Map1</styleUrl>
        </Pair>
        <Pair>
            <key>highlight</key>
            <styleUrl>#HighlightSheet1Map1</styleUrl>
        </Pair>
    </StyleMap>
    <Style id="HighlightSheet1Map1">
        <IconStyle>
            <scale>1.1</scale>
            <Icon>
                <href>http://www.earthpoint.us/Dots/GoogleEarth/paddle/ltblu-diamond.png</href>
            </Icon>
        </IconStyle>
        <LabelStyle>
            <scale>1.1</scale>
        </LabelStyle>
        <BalloonStyle>
            <text>$[description]</text>
        </BalloonStyle>
        <LineStyle>
            <color>ffff00ff</color>
            <width>3</width>
        </LineStyle>
        <PolyStyle>
            <color>70ff00ff</color>
            <fill>0</fill>
        </PolyStyle>
    </Style>
    <Folder>
        <name>Sheet1</name>
        <Placemark>
            <name>&lt;b/&gt;</name>
            <Snippet maxLines="0"></Snippet>
            <LookAt>
                <longitude>-7.899325</longitude>
                <latitude>53.41568611</latitude>
                <altitude>0</altitude>
                <heading>0</heading>
                <tilt>0</tilt>
                <range>1000</range>
                <altitudeMode>relativeToGround</altitudeMode>
            </LookAt>
            <styleUrl>#Sheet1Map1</styleUrl>
            <Style>
                <LabelStyle>
                    <color>00000000</color>
                </LabelStyle>
            </Style>
            <ExtendedData>
            </ExtendedData>
            <Point>
                <coordinates>-7.899325,53.41568611000001,0</coordinates>
            </Point>
        </Placemark>
        <Placemark>
            <name>&lt;b/&gt;</name>
            <Snippet maxLines="0"></Snippet>
            <LookAt>
                <longitude>-7.8991</longitude>
                <latitude>53.41593611</latitude>
                <altitude>0</altitude>
                <heading>0</heading>
                <tilt>0</tilt>
                <range>1000</range>
                <altitudeMode>relativeToGround</altitudeMode>
            </LookAt>
            <styleUrl>#Sheet1Map1</styleUrl>
            <Style>
                <LabelStyle>
                    <color>00000000</color>
                </LabelStyle>
            </Style>
            <ExtendedData>
            </ExtendedData>
            <Point>
                <coordinates>-7.8991,53.41593611,0</coordinates>
            </Point>
        </Placemark>
        <Placemark>
            <name>&lt;b/&gt;</name>
            <Snippet maxLines="0"></Snippet>
            <LookAt>
                <longitude>-7.900325</longitude>
                <latitude>53.41701111</latitude>
                <altitude>0</altitude>
                <heading>0</heading>
                <tilt>0</tilt>
                <range>1000</range>
                <altitudeMode>relativeToGround</altitudeMode>
            </LookAt>
            <styleUrl>#Sheet1Map1</styleUrl>
            <Style>
                <LabelStyle>
                    <color>00000000</color>
                </LabelStyle>
            </Style>
            <ExtendedData>
            </ExtendedData>
            <Point>
                <coordinates>-7.900325,53.41701111,0</coordinates>
            </Point>
        </Placemark>
    </Folder>
</Document>
</kml>

KML是XML。访问坐标的最简单方法是使用XML解析器。真正的问题是您做了什么,读取整个文件的代码是什么样子的?如果您理解linq,我觉得这是读取XML的最佳方法。