小编Ith*_*aca的帖子

C#中的XML - hasAttribute,getAttribute不存在?为什么?

我正在开展一个项目,要求我在一个单独的数据库中构建游戏的房间,物品和NPC.我选择了XML,但有些东西阻止我在C#代码中正确解析XML.我究竟做错了什么?

我的错误是这些:

System.xml.xmlnode does not contain a definition for HasAttribute 
Run Code Online (Sandbox Code Playgroud)

(这GetAttribute也适用)并且没有接受'HasAttribute'接受第一个类型参数的扩展方法System.Xml.XmlNode

这也是GetParentNode我的最后一行

string isMoveableStr = xmlRoom.GetAttribute("isMoveable");
Run Code Online (Sandbox Code Playgroud)

不知何故:

the name xmlRoom does not exist in the current context
Run Code Online (Sandbox Code Playgroud)

这是方法:

public void loadFromFile()
    {
        XmlDocument xmlDoc = new XmlDocument();              // create an xml document object in memory.
        xmlDoc.Load("gamedata.xml");                         // load the XML document from the specified file into the object in memory.

        // Get rooms, NPCs, and items.
        XmlNodeList xmlRooms = xmlDoc.GetElementsByTagName("room");
        XmlNodeList xmlNPCs …
Run Code Online (Sandbox Code Playgroud)

c# xml parsing

5
推荐指数
1
解决办法
2507
查看次数

标签 统计

c# ×1

parsing ×1

xml ×1