C# Unity 3D使用WWW类读取xml以传递到xml反序列化器

C# Unity 3D使用WWW类读取xml以传递到xml反序列化器,c#,android,xml,serialization,unity3d,C#,Android,Xml,Serialization,Unity3d,因此,我最近在这里遇到了一个问题,关于如何在我的android设备上找不到我的xml文件()我现在可以使用WWW类和Application.streamingassetpath找到该文件,通过这个,我现在可以让它访问该文件并通过xml反序列化器()运行它。然而,该程序仍然拒绝在我的Android设备上找到该文件。我的问题是:我哪里做错了 查找和读取文件的代码(反序列化与链接相同): private void XMLSerializerLoad() { 字符串路径; path=Applicatio

因此,我最近在这里遇到了一个问题,关于如何在我的android设备上找不到我的xml文件()我现在可以使用WWW类和Application.streamingassetpath找到该文件,通过这个,我现在可以让它访问该文件并通过xml反序列化器()运行它。然而,该程序仍然拒绝在我的Android设备上找到该文件。我的问题是:我哪里做错了

查找和读取文件的代码(反序列化与链接相同):

private void XMLSerializerLoad()
{
字符串路径;
path=Application.streamingAssetsPath+“/assets/”+_xmlFile.name+“.xml”;
打印(“从:+路径加载”);
start例程(MyRead(path));
}
IEnumerator MyRead(字符串路径)
{
ItemContainer\u项目;
打印(“访问文件:+路径”);
WWW=新WWW(路径);
收益率;
_items=ItemContainer.Load(www.url);
_拼写单词=新列表();//设置为空列表
_拼写单词=\项。\项;
}
注意:_spelling_words是类型项的全局列表,其中包含单词的字符串、年份组的int和单词描述的字符串

[编辑]

我还决定使用7-zip尝试提取apk以查找文件路径,并发现该文件实际上位于apk内的assets目录中,并且其中还有另一个assets目录也是同一个xml文件,我预计这是因为我是如何构造streaming assets文件夹的

[编辑]

XML示例:

    <word name="WINNER">
    <year>2</year> >
    <Description>A person that wins</Description>
    </word>

    <word name="HUGE">
    <year>2</year>
    <Description>Extraordinary large in quantity</Description>
    </word>

    <word name="TRUE">
    <year>2</year>
    <Description>The opposite of false</Description>
    </word>

    <word name="GREW"> 
    <year>2</year> >
    <Description>Past tense of grow</Description>
    </word>

2 >
胜利者
2.
数量巨大
2.
假的反面
2 >
grow的过去式
序列化程序示例

public class Item
{
    [XmlAttribute("name")]
    public string _name;
    [XmlElement("year")]
    public int _year;
    [XmlElement("Description")]
    public string _description;
}

[XmlRoot("spelling_game")]
public class ItemContainer
{
    [XmlArray("words"), XmlArrayItem("word")]
    public List<Item> _items = new List<Item> ();

    public void Save(string path)
    {
        var serializer = new XmlSerializer(typeof(ItemContainer));
        using(var stream = new FileStream(path, FileMode.Create))
        {
            serializer.Serialize(stream, this);
        }
    }

    public static ItemContainer Load(string path)
    {
        var serializer = new XmlSerializer(typeof(ItemContainer));
        using(var stream = new FileStream(path, FileMode.Open))
        {
            return serializer.Deserialize(stream) as ItemContainer;
        }
    }

    public static ItemContainer LoadFromText(string text) 
    {
        var serializer = new XmlSerializer(typeof(ItemContainer));
        return serializer.Deserialize(new StringReader(text)) as ItemContainer;
    }
}
公共类项目
{
[XmlAttribute(“名称”)]
公共字符串\u名称;
[XmlElement(“年度”)]
公共国际年;
[XmlElement(“描述”)]
公共字符串描述;
}
[XmlRoot(“拼写游戏”)]
公共类ItemContainer
{
[XmlArray(“文字”)、XmlArrayItem(“文字”)]
公共列表_items=新列表();
公共void保存(字符串路径)
{
var serializer=新的XmlSerializer(typeof(ItemContainer));
使用(var stream=newfilestream(路径,FileMode.Create))
{
serializer.Serialize(流,this);
}
}
公共静态ItemContainer加载(字符串路径)
{
var serializer=新的XmlSerializer(typeof(ItemContainer));
使用(var stream=newfilestream(路径,FileMode.Open))
{
返回序列化程序。反序列化(流)为ItemContainer;
}
}
公共静态ItemContainer LoadFromText(字符串文本)
{
var serializer=新的XmlSerializer(typeof(ItemContainer));
返回serializer.Deserialize(新的StringReader(文本))作为ItemContainer;
}
}

您的代码不显示您在哪里使用
XmlSerializer
。你能分享一下吗?另外,你能展示一个你想阅读的XML的例子吗?我在请求的代码中添加了你的代码没有显示你在哪里使用
XmlSerializer
。你能分享吗?另外,你能展示一个你想要阅读的XML的例子吗?我已经在请求的代码中添加了
public class Item
{
    [XmlAttribute("name")]
    public string _name;
    [XmlElement("year")]
    public int _year;
    [XmlElement("Description")]
    public string _description;
}

[XmlRoot("spelling_game")]
public class ItemContainer
{
    [XmlArray("words"), XmlArrayItem("word")]
    public List<Item> _items = new List<Item> ();

    public void Save(string path)
    {
        var serializer = new XmlSerializer(typeof(ItemContainer));
        using(var stream = new FileStream(path, FileMode.Create))
        {
            serializer.Serialize(stream, this);
        }
    }

    public static ItemContainer Load(string path)
    {
        var serializer = new XmlSerializer(typeof(ItemContainer));
        using(var stream = new FileStream(path, FileMode.Open))
        {
            return serializer.Deserialize(stream) as ItemContainer;
        }
    }

    public static ItemContainer LoadFromText(string text) 
    {
        var serializer = new XmlSerializer(typeof(ItemContainer));
        return serializer.Deserialize(new StringReader(text)) as ItemContainer;
    }
}