private static AtomContentValue ToTextValue(XmlElement node)
            {
                string type = node.GetAttribute("type");

                string mode = node.GetAttribute("mode");
                if (mode == string.Empty)
                    mode = "xml";

                string content;
                switch (mode)
                {
                    case "escaped":
                        content = node.InnerText;
                        break;
                    case "base64":
                        content = Encoding.UTF8.GetString(Convert.FromBase64String(node.InnerText));
                        break;
                    default:
                    case "xml":
                        content = node.InnerXml;
                        if (type == string.Empty && node.SelectSingleNode("./*") != null)
                            type = "application/xhtml+xml";
                        break;
                }

                AtomContentValue tv;
                switch (type)
                {
                    case "text/html":
                        tv = new AtomContentValue(AtomContentValueType.HTML, content);
                        break;
                    case "application/xhtml+xml":
                        XmlNamespaceManager nsMgr = new XmlNamespaceManager(new NameTable());
                        nsMgr.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml");

                        if (mode == "xml")
                        {
                            XmlNode div = node.SelectSingleNode("xhtml:div", nsMgr);
                            if (div != null)
                                tv = new AtomContentValue(AtomContentValueType.XHTML, div.InnerXml);
                            else
                                tv = new AtomContentValue(AtomContentValueType.XHTML, string.Empty);
                        }
                        else
                        {
                            tv = new AtomContentValue(AtomContentValueType.XHTML, content);
                        }
                        break;
                    default:
                    case "text/plain":
                        tv = new AtomContentValue(AtomContentValueType.Text, content);
                        break;
                }
                return tv;
            }
Пример #2
0
            private static AtomContentValue ToTextValue(XmlElement node)
            {
                string type = node.GetAttribute("type");

                string mode = node.GetAttribute("mode");

                if (mode == string.Empty)
                {
                    mode = "xml";
                }

                string content;

                switch (mode)
                {
                case "escaped":
                    content = node.InnerText;
                    break;

                case "base64":
                    content = Encoding.UTF8.GetString(Convert.FromBase64String(node.InnerText));
                    break;

                default:
                case "xml":
                    content = node.InnerXml;
                    if (type == string.Empty && node.SelectSingleNode("./*") != null)
                    {
                        type = "application/xhtml+xml";
                    }
                    break;
                }

                AtomContentValue tv;

                switch (type)
                {
                case "text/html":
                    tv = new AtomContentValue(AtomContentValueType.HTML, content);
                    break;

                case "application/xhtml+xml":
                    XmlNamespaceManager nsMgr = new XmlNamespaceManager(new NameTable());
                    nsMgr.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml");

                    if (mode == "xml")
                    {
                        XmlNode div = node.SelectSingleNode("xhtml:div", nsMgr);
                        if (div != null)
                        {
                            tv = new AtomContentValue(AtomContentValueType.XHTML, div.InnerXml);
                        }
                        else
                        {
                            tv = new AtomContentValue(AtomContentValueType.XHTML, string.Empty);
                        }
                    }
                    else
                    {
                        tv = new AtomContentValue(AtomContentValueType.XHTML, content);
                    }
                    break;

                default:
                case "text/plain":
                    tv = new AtomContentValue(AtomContentValueType.Text, content);
                    break;
                }
                return(tv);
            }
            private static AtomContentValue ToTextValue(IXmlNode node)
            {
                string type = (string)node.Attributes.SingleOrDefault(a => a.NodeName == "type").NodeValue;

                string mode = (string)node.Attributes.SingleOrDefault(a => a.NodeName == "mode")?.NodeValue;

                if (string.IsNullOrEmpty(mode))
                {
                    mode = "xml";
                }

                string content;

                switch (mode)
                {
                case "escaped":
                    content = node.InnerText;
                    break;

                case "base64":
                    content = Encoding.UTF8.GetString(Convert.FromBase64String((string)node.NodeValue));
                    break;

                default:
                case "xml":
                    content = node.InnerText;
                    if (type == string.Empty && node.SelectSingleNode("./*") != null)
                    {
                        type = "application/xhtml+xml";
                    }
                    break;
                }

                AtomContentValue tv;

                switch (type)
                {
                case "text/html":
                    tv = new AtomContentValue(AtomContentValueType.HTML, content);
                    break;

                case "application/xhtml+xml":
                    XmlNamespaceManager nsMgr = new XmlNamespaceManager(new NameTable());
                    nsMgr.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml");

                    if (mode == "xml")
                    {
                        var div = node.SelectSingleNodeNS("xhtml:div", nsMgr.ToNSMethodFormat());
                        if (div != null)
                        {
                            tv = new AtomContentValue(AtomContentValueType.XHTML, (string)div.NodeValue);
                        }
                        else
                        {
                            tv = new AtomContentValue(AtomContentValueType.XHTML, string.Empty);
                        }
                    }
                    else
                    {
                        tv = new AtomContentValue(AtomContentValueType.XHTML, content);
                    }
                    break;

                default:
                case "text/plain":
                    tv = new AtomContentValue(AtomContentValueType.Text, content);
                    break;
                }
                return(tv);
            }