我正在尝试通过管道将 XML 文件加载到我的 MonoGame 游戏中,但出现错误。
“元素”是无效的 XmlNodeType。第 10 行,第 6 位。
我在一个外部可移植类库项目中为 XML 文件创建了我的类,并将该 DLL 添加到管道内容引用中。但是当我尝试在 MonoGame Pipeline 应用程序中构建 XML 文件时,我得到了上述错误。
有任何想法吗?
XML和类代码如下
MainMenu.xml(我已经用 xml 样式注释标记了错误行,注释不在实际文件中)
<?xml version="1.0" encoding="utf-8"?>
<XnaContent xmlns:ns="Microsoft.Xna.Framework">
<Asset Type="Menu">
<Title>Main Menu</Title>
<Background>
<Type>animation</Type>
<Data>MainMenuBackground</Data>
</Background>
<Options>
<Option> <!-- Error Here -->
<Type>text</Type>
<Name>new</Name>
<Disabled>false</Disabled>
<Text>New Game</Text>
<Action>newGame</Action>
</Option>
<Option>
<Type>text</Type>
<Name>save</Name>
<Disabled>true</Disabled>
<Text>Save Game</Text>
<Action>saveGame</Action>
</Option>
<Option>
<Type>text</Type>
<Name>load</Name>
<Disabled>false</Disabled>
<Text>Load Game</Text>
<Action>loadGame</Action>
</Option>
<Option>
<Type>text</Type>
<Name>exit</Name>
<Disabled>false</Disabled>
<Text>Exit Game</Text>
<Action>exitGame</Action>
</Option>
</Options>
<Buttons>
<Keyboard>
<Accept>Enter</Accept>
<Cancel>Esc</Cancel>
</Keyboard>
<Controller>
<Accept>A</Accept>
<Cancel>B</Cancel>
</Controller>
</Buttons>
</Asset>
</XnaContent>
菜单.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace XMLMenu
{
public class Menu
{
public String Title;
public Background Background = new Background();
public Option[] Options = new Option[] { };
public Buttons Buttons = new Buttons();
}
}
背景.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace XMLMenu
{
public class Background
{
public String Type;
public String Data;
}
}
选项.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace XMLMenu
{
public class Option
{
public String Type;
public String Name;
public Boolean Disabled;
public String Text;
public string Action;
}
}
按钮.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace XMLMenu
{
public class Buttons
{
public ControlButtons Keyboard = new ControlButtons();
public ControlButtons Controller = new ControlButtons();
}
}
控制按钮.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace XMLMenu
{
public class ControlButtons
{
public String Accept;
public String Cancel;
}
}