Get a heading from an XForm

Vote:
 

I've created a poll XForm containing a heading with a question, a set of radio buttons for alternatives and a button to submit to the poll. I'd like to extract the heading of that XForm that represents the question. How would I do that? I've gotten as far as to create an instance of the XForm by XForm form = XForm.CreateInstance(new Guid((String)page["XForm"])); but is it now possible to get parts of that XForm out of it?

 

#37063
Feb 18, 2010 14:38
Vote:
 

I found a way to do this from a link that I can't seem to find at the moment so if anybody know what site this could be the author would probably appreciate the credit. :)

        public string GetQuestion(PageData page)
        {
            XForm form = XForm.CreateInstance(new Guid((String)page["XForm"]));
            SerializableXmlDocument doc = form.Document;
            XDocument xmlDoc = XDocument.Parse(doc.InnerXml);

            string question = string.Empty;

            try
            {
                var headingQuery = from q in xmlDoc.Descendants("span")
                                   where q.Attribute("class").Value.Contains("Heading")
                                   select new { heading = q.Value };
                question = (string)(headingQuery.ElementAt(0).heading);
            }
            finally
            {
                if (question.Length == 0)
                    question = "";
            }

            return question;
        }

#37115
Feb 22, 2010 9:04
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.