我正在尝试将变量从我的主要活动传递到片段.这就是我试图这样做的方式:
这是我的活动:
Bundle args = new Bundle ();
args.PutString ("header", header);
args.PutString ("content", content);
args.PutString ("footer", header);
args.PutString ("imageLocation", imageLocation);
exhibitMainFragment.Arguments = args;
FragmentManager.BeginTransaction ()
.Replace (Resource.Id.main_view, exhibitMainFragment)
.AddToBackStack (null)
.Commit ();
Run Code Online (Sandbox Code Playgroud)
这是我的片段:
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Android.OS.Bundle savedInstanceState)
{
var ignored = base.OnCreateView(inflater, container, savedInstanceState);
var view = inflater.Inflate(Resource.Layout.MuseumInformation, null);
content = this.Activity.Intent.GetStringExtra ("content");
header = this.Activity.Intent.GetStringExtra ("header");
footer = this.Activity.Intent.GetStringExtra ("footer");
imageFilePath = this.Activity.Intent.GetStringExtra ("imageLocation");
Run Code Online (Sandbox Code Playgroud)
但是没有传递任何变量(它们在片段中都是空的).我在这里显然犯了一个根本性的错误.有人能告诉我它是什么吗?或者向我展示一种更好的方法来传递数据.
谢谢.
在我被人们认为XML解析器不应该关心元素是空的还是自闭的之前,有一个原因是我不能允许自闭XML元素.原因是我实际上使用的是SGML而不是XML,而我正在使用的SGML DTD非常严格并且不允许它.
我所拥有的是数千个SGML文件,我需要运行XSLT.因此,我必须暂时将SGML转换为XML才能应用XSLT.然后我编写了一个方法,将它们转换回SGML(基本上只是用SGML声明替换XML声明并写回任何其他实体声明,如图形实体).
我的问题是,在转换回SGML之后,当我在SGML编辑器中打开文件时,文件不会解析,因为空元素已经自动关闭.
有没有人知道如何在使用XmlDocument时阻止这种情况发生?
将SGML转换为XML并再次返回的方法如下所示
//converts the SGML file to XML – it’s during this conversion that the
//empty elements get self-closed, i think
private XmlDocument convertToXML(TextReader reader)
{
// setup SgmlReader
Sgml.SgmlReader sgmlReader = new Sgml.SgmlReader();
//sgmlReader.DocType = "HTML";
sgmlReader.WhitespaceHandling = WhitespaceHandling.All;
sgmlReader.CaseFolding = Sgml.CaseFolding.ToLower;
sgmlReader.InputStream = reader;
// create document
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
doc.XmlResolver = null;
doc.Load(sgmlReader);
return doc;
}
// method to apply the XSLT stylesheet to the XML document
private …Run Code Online (Sandbox Code Playgroud)