locked
display attribute xml in listview RRS feed

  • Question

  • User-646447061 posted

    <itunes:category text="Religion & Spirituality"/>

    i want to get text "Religion & Spirituality" can you help me ?  i try to write like this <%# XPath("itunes:category/@text")%> but can't ..

    Friday, December 18, 2015 8:30 AM

Answers

  • User1578460427 posted

    Try replacing the & with the HTML name.

    <itunes:category text="Religion &amp; Spirituality"/>

    Or try replacing the & with HTML number.

    <itunes:category text="Religion &#38; Spirituality"/>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 20, 2015 12:31 PM

All replies

  • User1578460427 posted

    Try replacing the & with the HTML name.

    <itunes:category text="Religion &amp; Spirituality"/>

    Or try replacing the & with HTML number.

    <itunes:category text="Religion &#38; Spirituality"/>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 20, 2015 12:31 PM
  • User-271186128 posted

    Hi motorrevo00,

    You could refer to the following code to read xml node with attribute:

    Xml file:

    <?xml version="1.0" encoding="utf-8" ?>
    <Questions>
      <Question id="1" type='Single  &amp; Choice'>
        <Text>Where is your project primarily located? (select only one)</Text>
        <Answers>
          <Answer id="1"> In an urbanized area</Answer>
          <Answer id="2"> In a metropolitan area outside of core urbanized area </Answer>
          <Answer id="3"> In a small city/town</Answer>
          <Answer id="4"> In a rural area</Answer>
        </Answers>
      </Question>
      <Question id="2" type='Single  &amp; Choice'>
        <QuestionType>SingleChoice</QuestionType>
        <Text>What neighborhood is the project located in? (select only one)</Text>
        <Answers>
          <Answer id="1">Primarily a residential area</Answer>
          <Answer id="2">Primarily an employment area</Answer>
          <Answer id="3">Primarily an industrial/warehousing area</Answer>
        </Answers>
      </Question>
    </Questions>

    Code in page (.aspx.cs)

                XmlDocument xml = new XmlDocument();
                xml.Load(Server.MapPath("Questions.xml"));
                StringBuilder sb = new StringBuilder();
    
                List<DiagnosticTool> queslist = new List<DiagnosticTool>();
    
                XmlNodeList list = xml.SelectNodes("/Questions/Question");
                foreach (XmlNode xn in list)
                {
                    DiagnosticTool dt = new DiagnosticTool();
                    dt.QuestionId = Convert.ToInt32(xn.Attributes["id"].Value); //Get Question Id                
                    dt.QuestionType = xn.Attributes["type"].Value;  //Get Question Type
                    dt.Text = xn["Text"].InnerText; //Get Text Node
    
                    sb.AppendLine(dt.QuestionId.ToString());
                    sb.AppendLine("\t");
                    sb.AppendLine(dt.QuestionType);
                    sb.AppendLine("\t");
                    sb.AppendLine(dt.Text);
                    sb.AppendLine("<br />");
    
                    List<Answer> answerlist = new List<Answer>();
                    XmlNodeList list2 = xn.SelectNodes(".//Answers/Answer");
                    foreach (XmlNode xn2 in list2)
                    {
                        Answer an = new Answer();
                        an.AnswerId = Convert.ToInt32(xn2.Attributes["id"].Value);//Get answer id.
                        an.Text = xn2.InnerText;//Get answer node.
    
                        answerlist.Add(an); //add answer to List
    
                        sb.AppendLine(an.AnswerId.ToString());
                        sb.AppendLine("\t");
                        sb.AppendLine(an.Text);
                        sb.AppendLine("<br />");
                    }
    
                    dt.Answers = answerlist;
    
                    queslist.Add(dt); // Add question to list
    
                    sb.AppendLine("<br />");

    The output:

    1 Single & Choice Where is your project primarily located? (select only one)
    1 In an urbanized area
    2 In a metropolitan area outside of core urbanized area
    3 In a small city/town
    4 In a rural area

    2 Single & Choice What neighborhood is the project located in? (select only one)
    1 Primarily a residential area
    2 Primarily an employment area
    3 Primarily an industrial/warehousing area

    Best regards,
    Dillion

    Monday, December 21, 2015 6:38 AM