[英]Mono for Android: XML data to spinner
My XML Example: 我的XML示例:
<Table diffgr:id="Table17" msdata:rowOrder="16">
<IdRec>17</IdRec>
<FieldId>1213</FieldId>
<FieldDesc>Equipment</FieldDesc>
<FieldType>OptionBOX</FieldType>
<isReadOnly>false</isReadOnly>
<FieldValue>388</FieldValue>
<FieldTextValue>B - satisfactory</FieldTextValue>
<OptBox_Options>
<Options>
<myOPT FieldValue="387" FieldTextValue="A - good"/>
<myOPT FieldValue="388" FieldTextValue="B - satisfactory"/>
<myOPT FieldValue="389" FieldTextValue="C - needs change"/>
<myOPT FieldValue="390" FieldTextValue="D - deal"/>
</Options>
</OptBox_Options>
</Table>
My problem The above xml data comes from a webservice. 我的问题上面的xml数据来自Web服务。 I have no problem with any field other than OptBox_Options which is a field I need to use to populate my spinner.
除OptBox_Options外,我对任何其他字段都没有问题,这是我需要用来填充微调器的字段。 Ergo I need to get the string from OptBox_Options->Options->myOpt(FieldTextValue) (for example: ).
因此,我需要从OptBox_Options-> Options-> myOpt(FieldTextValue)中获取字符串(例如:)。
How to access this data? 如何访问这些数据? What would be the best approach.
最好的方法是什么。 If you can't give me a direct solution I would be satisfied with a link to noob friendly C# tutorial on the subject.
如果您不能给我直接解决方案,我将为您提供与此主题相关的Noob友好C#教程链接。
Isssue Resolved 问题已解决
I transformed my string to XML, then converted it to a dataset and just cycled through it... Code below :) 我将字符串转换为XML,然后将其转换为数据集,并在其中循环...下面的代码:)
List<string> entries = new List<string>();
String rawXML = item.OptBox_Options;
StringReader stream = null;
XmlTextReader reader = null;
DataSet xmlDS = new DataSet();
stream = new StringReader(rawXML);
// Load the XmlTextReader from the stream
reader = new XmlTextReader(stream);
xmlDS.ReadXml(reader);
DataSet myOPTvalues = new DataSet();
myOPTvalues = xmlDS;
foreach (DataRow row in myOPTvalues.Tables[0].Rows)
{
var optItem = new PrevzemSpin();
optItem.FieldValue = row["FieldValue"].ToString();
if (optItem.FieldValue.Equals("")) optItem.FieldValue = null;
optItem.FieldTextValue = row["FieldTextValue"].ToString();
if (optItem.FieldTextValue.Equals("")) optItem.FieldTextValue = null;
entries.Add(optItem.FieldTextValue);
SpinnerValue.Tag = optItem.FieldValue;
}
I transformed my string to XML, then converted it to a dataset and just cycled through it... Code below :) 我将字符串转换为XML,然后将其转换为数据集,并在其中循环...下面的代码:)
List<string> entries = new List<string>();
String rawXML = item.OptBox_Options;
StringReader stream = null;
XmlTextReader reader = null;
DataSet xmlDS = new DataSet();
stream = new StringReader(rawXML);
// Load the XmlTextReader from the stream
reader = new XmlTextReader(stream);
xmlDS.ReadXml(reader);
DataSet myOPTvalues = new DataSet();
myOPTvalues = xmlDS;
foreach (DataRow row in myOPTvalues.Tables[0].Rows)
{
var optItem = new PrevzemSpin();
optItem.FieldValue = row["FieldValue"].ToString();
if (optItem.FieldValue.Equals("")) optItem.FieldValue = null;
optItem.FieldTextValue = row["FieldTextValue"].ToString();
if (optItem.FieldTextValue.Equals("")) optItem.FieldTextValue = null;
entries.Add(optItem.FieldTextValue);
SpinnerValue.Tag = optItem.FieldValue;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.