如何找出nodeType是什么?
我正在尝试从 google API 位置读取 XML 文件并添加到结构中,但我在使用 C# 时遇到了一些问题,因为我是新手... 我有一个像这样的 XML 文件:
<PlaceSearchResponse>
<status>OK</status>
<result>
<name>Williamsburg</name>
<type>locality</type>
<type>political</type>
<icon>http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png</icon>
<reference>CkRAAAAAUhZG...Yy0b4-sd1zCUu9P8</reference>
</result>
<result>
<name>Greenpoint</name>
<vicinity>New York</vicinity>
<type>neighborhood</type>
<type>political</type>
<icon>http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png</icon>
<reference>CkQ-AAAAHIDo...nYmSR8l52FmkMH6c</reference>
<name>Peter Luger Steakhouse</name>
<vicinity>Broadway, Brooklyn</vicinity>
<type>restaurant</type>
<type>food</type>
<type>establishment</type>
<icon>http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png</icon>
<reference>ClRBAAAATIpR...mHSxoyiRcr_FVuww</reference>
</result>
...additional results...
</PlaceSearchResponse>
我需要循环所有节点并添加到列表中。像这样的事情:
while (nodetype == "type")
{
PlaceType t = new PlaceType();
t.name = x.Element("type").Value;
place.types.Add(t);
}
另外,我的班级地点:
public class Place
{
public string name { get; set; }
public List<PlaceType> types { get; set; }
public string vicinity { get; set; }
public string icon { get; set; }
public string reference { get; set; }
}
Im trying to read a XML file from google API places and add to a structure, but im having some problems with C# because im new at it...
I have a XML file like this:
<PlaceSearchResponse>
<status>OK</status>
<result>
<name>Williamsburg</name>
<type>locality</type>
<type>political</type>
<icon>http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png</icon>
<reference>CkRAAAAAUhZG...Yy0b4-sd1zCUu9P8</reference>
</result>
<result>
<name>Greenpoint</name>
<vicinity>New York</vicinity>
<type>neighborhood</type>
<type>political</type>
<icon>http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png</icon>
<reference>CkQ-AAAAHIDo...nYmSR8l52FmkMH6c</reference>
<name>Peter Luger Steakhouse</name>
<vicinity>Broadway, Brooklyn</vicinity>
<type>restaurant</type>
<type>food</type>
<type>establishment</type>
<icon>http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png</icon>
<reference>ClRBAAAATIpR...mHSxoyiRcr_FVuww</reference>
</result>
...additional results...
</PlaceSearchResponse>
And i need to loop all the nodes and add to a list. Something like this:
while (nodetype == "type")
{
PlaceType t = new PlaceType();
t.name = x.Element("type").Value;
place.types.Add(t);
}
Also, my class Place:
public class Place
{
public string name { get; set; }
public List<PlaceType> types { get; set; }
public string vicinity { get; set; }
public string icon { get; set; }
public string reference { get; set; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面将把所有类型提取到一个字符串数组中。
The following will pull out all types into a string array.