3

タイプの文字列がありますstring xml = @"<recurrence><rule><firstDayOfWeek>mo</firstDayOfWeek><repeat><daily dayFrequency=""1"" /></repeat><windowEnd>2012-10-31T10:00:00Z</windowEnd></rule></recurrence>";

dayFrequencyここにある値を読み取りたいのですが、タグの下で1直接読み取る方法はありますか? 同様に、a="1"、b="King"などのタグがたくさんあるので、値を直接読み取りたい変数に割り当てられます。dayFrequencydaily

親切に助けてください。

繰り返しタグを読み取る以下のコードを使用しました

string xml = @"<recurrence><rule><firstDayOfWeek>mo</firstDayOfWeek><repeat><daily dayFrequency=""1"" /></repeat><windowEnd>2012-10-31T10:00:00Z</windowEnd></rule></recurrence>";

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);

// this would select all title elements
XmlNodeList titles = xmlDoc.GetElementsByTagName("repeat"); 
4

5 に答える 5

3
XDocument xmlDoc = XDocument.Parse(xml);
var val = xmlDoc.Descendants("daily")
                .Attributes("dayFrequency")
                .FirstOrDefault();

ここで、valは次のようになります。

val = {dayFrequency="1"}

val.Valueあなたに与える1

于 2012-10-30T10:28:59.620 に答える
2
XElement.Parse(xml).Descendants("daily")
                   .Single()
                   .Attribute("dayFrequency")
                   .Value;
于 2012-10-30T10:25:18.357 に答える
1
XDocument xdoc = XDocument.Parse(@"<recurrence><rule><firstDayOfWeek>mo</firstDayOfWeek><repeat><daily dayFrequency=""1"" /></repeat><windowEnd>2012-10-31T10:00:00Z</windowEnd></rule></recurrence>");
        string result = xdoc
            .Descendants("recurrence")
            .Descendants("rule")
            .Descendants("repeat")
            .Descendants("daily")
            .Attributes("dayFrequency")
            .First()
            .Value;
于 2012-10-30T10:36:05.323 に答える
0
    var nodes = xmlDoc.SelectNodes(path);

    foreach (XmlNode childrenNode in nodes)
    {
        HttpContext.Current.Response.Write(childrenNode.SelectSingleNode("//repeat").Value);
    } 
于 2012-10-30T10:26:23.723 に答える
0
于 2012-10-30T10:25:40.723 に答える