1

このコードは私には機能せず、その理由がわかりません。

xmlDoc.Element("results").Add(
                new XElement("user",
                    new XAttribute("id", user.Id),
                    new XAttribute("facebookid", user.FacebookId),
                    new XAttribute("email", user.Email),
                    new XAttribute("totalpoints", totalpoints)
                    ).Add(
                            user.Answers.Select(value => new XElement("question",
                            new XAttribute("id", value.QuestionId),
                            new XAttribute("answer_id", value.AnswerId),
                            new XAttribute("points", value.Points)))
                          )
                  );

私はこれを作成しようとしています

<results>
  <user id="2323" facebookId="3254954795743957" email="david@gmail" totalPoints="">
    <question id="1" answer_id="3" points="0" />
    <question id="2" answer_id="1" points="1" />
  </user>
</results>
4

1 に答える 1

1
xmlDoc.Element("results").Add(
    new XElement("user",
        new XAttribute("id", user.Id),
        new XAttribute("facebookid", user.FacebookId),
        new XAttribute("email", user.Email),
        new XAttribute("totalpoints", totalpoints),
        user.Answers.Select(value => new XElement(
                "question",
                new XAttribute("id", value.QuestionId),
                new XAttribute("answer_id", value.AnswerId),
                new XAttribute("points", value.Points)
            ))
        )
    );

問題は、Addメソッドが返されるため、結果voidに対して別のメソッドを続行できないことです。また、属性にはではなくを使用する必要があります。AddvoidXAttributeXElement

于 2012-08-21T10:05:19.233 に答える