그래서, 나는이 같은 XML이 자식 노드의 속성을 가져 오기 :C#의 XML 파싱 -
<tileset firstgid="1" name="simple_tiles" tilewidth="32" tileheight="32" tilecount="16" columns="8">
<image source="../Users/mkkek/Pictures/rpg/default_tiles_x.png" width="256" height="64"/>
</tileset>
나는 tileset
노드에있어, 어떻게이 image
노드와 노드의 source
속성에 액세스 할 수 있습니까? 내 코드는 다음과 같습니다 :
public void LoadMaps(ContentManager content)
{
Dictionary<string, string> mapsToLoad = InitMapsToLoad();
foreach (KeyValuePair<string, string> mapToLoad in mapsToLoad)
{
Map map = new Map();
map.Name = Path.GetFileNameWithoutExtension(mapToLoad.Value);
reader = XmlReader.Create("Content/" + mapToLoad.Value);
while(reader.Read())
{
if(reader.NodeType == XmlNodeType.Element)
{
switch(reader.Name)
{
case "tileset":
if(!Tilesets.Any(ts => ts.Name == reader.GetAttribute("name")))
{
// handling the image node here
}
break;
}
}
}
}
}
XmlReader를 사용하는 이유는 무엇입니까? XML에 대한 LINQ? – YuvShap
아니, 사용해야합니까? 그것은'System.Xml.Linq' 네임 스페이스에 액세스 할 수없는 것 같습니다. – mkkekkonen
이제 그것을 찾았습니다. 참조로 추가해야했습니다. – mkkekkonen