【发布时间】:2016-04-15 06:34:57
【问题描述】:
<?xml version='1.0' encoding='ISO-8859-1' standalone='yes'?>
<Collection>
<Book Id='1' ISBN='1-100000ABC-200'>
<Title>Principle of Relativity</Title>
<!-- Famous physicist -->
<Author>Albert Einstein</Author>
<Genre>Physics</Genre>
</Book>
<Book Id='2' ISBN='1-100000ABC-300'>
<!-- Also came as a TV serial -->
<Title>Cosmos</Title>
<Author>Carl Sagan</Author>
<Genre>Cosmology</Genre>
</Book>
<!-- Add additional books here -->
</Collection>
当应用程序在 3 秒后启动时,会发生此异常:
System.Xml.XmlException:根级别的数据无效。第 1 行,位置 1
为什么在此 XML 代码正确并在控制台应用程序中加载并且控制台应用程序中没有发生异常时发生此异常。
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.Xml;
using System.Xml.Linq;
using System.Linq;
namespace App16
{
[Activity(Label = "App16", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
int count = 1;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
XmlDocument doc = new XmlDocument();
doc.LoadXml("Q317664.xml");
// var doc = XDocument.Load("Q317664.xml");
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
}
}
}
【问题讨论】:
标签: xml xamarin.android