Ejemplo n.º 1
0
        public static string CreateDescriptiveQuestion(XElement questionIterator, Category parent, XDocument xmlDocument)
        {
            var questionId = questionIterator.Name.LocalName;

            var constraint = xmlDocument.Element(Namespaces.XHtmlNamespace + "html").Element(Namespaces.XHtmlNamespace + "head")
                             .Element(Namespaces.DefaultNamespace + "model").Elements(Namespaces.DefaultNamespace + "bind").ToList()
                             .Where(e => e.Attribute("nodeset").Value.Equals(string.Format("/data/{0}/{1}", parent.SystemID, questionId))).Single().Attribute("constraint");

            var length = 255;

            if (constraint != null)
            {
                var contraints   = GetConstraints(constraint.Value, @"string-length\( \. \) <=(?'length'\d+)");
                var lengthString = contraints["length"];

                if (!string.IsNullOrEmpty(lengthString))
                {
                    length = int.Parse(lengthString);
                }
            }

            var defaultAnswer = questionIterator.Value;

            var required = xmlDocument.Element(Namespaces.XHtmlNamespace + "html").Element(Namespaces.XHtmlNamespace + "head")
                           .Element(Namespaces.DefaultNamespace + "model").Elements(Namespaces.DefaultNamespace + "bind").ToList()
                           .Where(e => e.Attribute("nodeset").Value.Equals(string.Format("/data/{0}/{1}", parent.SystemID, questionId))).Single().Attribute("required");

            var isRequired = false;

            if (required != null)
            {
                isRequired = GetRequired(required.Value, @"\w+");
            }

            var label = xmlDocument.Element(Namespaces.XHtmlNamespace + "html").Element(Namespaces.XHtmlNamespace + "head")
                        .Element(Namespaces.DefaultNamespace + "model").Element(Namespaces.DefaultNamespace + "itext").Element(Namespaces.DefaultNamespace + "translation")
                        .Elements().ToList().Where(e => e.Attribute("id").Value.Equals(string.Format("/data/{0}/{1}:label", parent.SystemID, questionId))).Single().Element(Namespaces.DefaultNamespace + "value").Value;
            var descriptiveQuestionData = new DescriptiveQuestionData
            {
                Label     = label,
                Answer    = defaultAnswer,
                MaxLength = length,
                Required  = isRequired,
            };

            return(new TypedXmlSerializer <DescriptiveQuestionData>().SerializeToXmlString(descriptiveQuestionData));
        }
        public static string CreateDescriptiveQuestion(XElement questionIterator, Category parent, XDocument xmlDocument)
        {
            var questionId = questionIterator.Name.LocalName;

            var constraint = xmlDocument.Element(Namespaces.XHtmlNamespace + "html").Element(Namespaces.XHtmlNamespace + "head")
                    .Element(Namespaces.DefaultNamespace + "model").Elements(Namespaces.DefaultNamespace + "bind").ToList()
                    .Where(e => e.Attribute("nodeset").Value.Equals(string.Format("/data/{0}/{1}", parent.SystemID, questionId))).Single().Attribute("constraint");

            var length = 255;

            if (constraint != null)
            {
                var contraints = GetConstraints(constraint.Value, @"string-length\( \. \) <=(?'length'\d+)");
                var lengthString = contraints["length"];

                if (!string.IsNullOrEmpty(lengthString))
                    length = int.Parse(lengthString);
            }

            var defaultAnswer = questionIterator.Value;

            var required = xmlDocument.Element(Namespaces.XHtmlNamespace + "html").Element(Namespaces.XHtmlNamespace + "head")
                    .Element(Namespaces.DefaultNamespace + "model").Elements(Namespaces.DefaultNamespace + "bind").ToList()
                    .Where(e => e.Attribute("nodeset").Value.Equals(string.Format("/data/{0}/{1}", parent.SystemID, questionId))).Single().Attribute("required");

            var isRequired = false;

            if (required != null)
            {
                isRequired = GetRequired(required.Value, @"\w+");
            }

            var label = xmlDocument.Element(Namespaces.XHtmlNamespace + "html").Element(Namespaces.XHtmlNamespace + "head")
                    .Element(Namespaces.DefaultNamespace + "model").Element(Namespaces.DefaultNamespace + "itext").Element(Namespaces.DefaultNamespace + "translation")
                    .Elements().ToList().Where(e => e.Attribute("id").Value.Equals(string.Format("/data/{0}/{1}:label", parent.SystemID, questionId))).Single().Element(Namespaces.DefaultNamespace + "value").Value;
            var descriptiveQuestionData = new DescriptiveQuestionData
            {
                Label = label,
                Answer = defaultAnswer,
                MaxLength = length,
                Required = isRequired,
            };
            return new TypedXmlSerializer<DescriptiveQuestionData>().SerializeToXmlString(descriptiveQuestionData);
        }