[Unity3D]适用于UWP的XmlDocument使用方法

上一篇讲了在Unity3D中UWP可以使用的XML的序列化的方法。
上文链接:[Unity3D]在UWP工程中使用的序列化方法
但是XmlReader和XmlWriter使用起来很麻烦,所以本篇演示XmlDocument既可在UWP中使用又可在Unity3D编辑器中使用的方法。

UWP和Unity3D都支持XmlDocument类,但由于程序集的不同,有些在Unity3D中可以用的方法在UWP中无法使用,最终导致在编译UWP工程时失败。比如XmlDocument.Load方法在UWP中就没有通过文件路径调用的重载。

uwp 中的XmlDocument.Load:
这里写图片描述

unity3D 中的XmlDocument.Load:
这里写图片描述

所以在实际编程中,最好只使用两者都支持的方法。

下面UWP和Unity3D都支持的使用方法:

using UnityEngine;
using System.Xml;
using System.Text;

//利用宏定义区分Unity3D与UWP的引用空间
#if NETFX_CORE
using Windows.Storage;
using System.IO;
using XmlReader = WinRTLegacy.Xml.XmlReader;
using XmlWriter = WinRTLegacy.Xml.XmlWriter;
using StreamWriter = WinRTLegacy.IO.StreamWriter;
using StreamReader = WinRTLegacy.IO.StreamReader;
#else
using XmlReader = System.Xml.XmlReader;
using XmlWriter = System.Xml.XmlWriter;
using StreamWriter = System.IO.StreamWriter;
using StreamReader = System.IO.StreamReader;
#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值