CreateElementNS() public method

public CreateElementNS ( [ namespaceUri, [ qualifiedName ) : XmlElement
namespaceUri [
qualifiedName [
return XmlElement
コード例 #1
0
            public override XmlElement CreateCategoryElement(XmlDocument ownerDoc, string category, string categoryScheme, string categoryLabel)
            {
                XmlElement element = ownerDoc.CreateElementNS(DC_URI, "dc:subject");

                element.InnerText = category;
                return(element);
            }
コード例 #2
0
            public override XmlElement PlaintextToTextNode(XmlDocument ownerDoc, string text)
            {
                XmlElement el = ownerDoc.CreateElementNS(NamespaceUri, "atom:content");

                el.SetAttribute("type", "text");
                el.InnerText = text;
                return(el);
            }
コード例 #3
0
            public override XmlElement HtmlToTextNode(XmlDocument ownerDoc, string html)
            {
                XmlElement el = ownerDoc.CreateElementNS(NamespaceUri, "atom:content");

                el.SetAttribute("type", "html");
                el.InnerText = html;
                return(el);
            }
コード例 #4
0
            public override XmlElement CreateCategoryElement(XmlDocument ownerDoc, string category, string categoryScheme, string categoryLabel)
            {
                if (categoryScheme == null)
                {
                    throw new ArgumentException("Null category scheme not supported");
                }

                XmlElement element = ownerDoc.CreateElementNS(NamespaceUri, "atom:category");

                element.SetAttribute("term", category);
                if (categoryScheme.Length > 0)
                {
                    element.SetAttribute("scheme", categoryScheme);
                }
                element.SetAttribute("label", categoryLabel);
                return(element);
            }
コード例 #5
0
        /// <summary>
        /// Converts an html string into xaml string.
        /// </summary>
        /// <param name="htmlString">
        /// Input html which may be badly formated xml.
        /// </param>
        /// <param name="asFlowDocument">
        /// true indicates that we need a FlowDocument as a root element;
        /// false means that Section or Span elements will be used
        /// dependeing on StartFragment/EndFragment comments locations.
        /// </param>
        /// <returns>
        /// Well-formed xml representing XAML equivalent for the input html string.
        /// </returns>
        public static string ConvertHtmlToXaml(string htmlString, bool asFlowDocument)
        {
            // Create well-formed Xml from Html string
            XmlElement htmlElement = HtmlParser.ParseHtml(htmlString);

            // Decide what name to use as a root
               // string rootElementName = asFlowDocument ? HtmlToXamlConverter.Xaml_FlowDocument : HtmlToXamlConverter.Xaml_Section;
            string rootElementName = asFlowDocument
                ? HtmlToXamlConverter.Xaml_FlowDocument
                : "RichTextBlock";
            // Create an XmlDocument for generated xaml
            var xamlTree = new XmlDocument();
               // var d = xamlTree.CreateAttributeNS("App5.Utils", "utils:xd");
            XmlElement xamlFlowDocumentElement = xamlTree.CreateElementNS( _xamlNamespace,rootElementName);

              //  xamlFlowDocumentElement.SetAttribute("xmlns:space", "App5.Utils");
            // Extract style definitions from all STYLE elements in the document
            CssStylesheet stylesheet = new CssStylesheet(htmlElement);

            // Source context is a stack of all elements - ancestors of a parentElement
            List<XmlElement> sourceContext = new List<XmlElement>(10);

            // Clear fragment parent
            InlineFragmentParentElement = null;

            // convert root html element
            AddBlock(xamlFlowDocumentElement, htmlElement, new Dictionary<string ,string>(), stylesheet, sourceContext);

            // In case if the selected fragment is inline, extract it into a separate Span wrapper
            if (!asFlowDocument)
            {
                xamlFlowDocumentElement = ExtractInlineFragment(xamlFlowDocumentElement);
            }

            // Return a string representing resulting Xaml
            //xamlFlowDocumentElement.SetAttribute("xml:space", "preserve");
            var xaml = xamlFlowDocumentElement.GetXml();

            return xaml;
        }
コード例 #6
0
        public async Task <string> NewPost(string blogId, BlogPost post, INewCategoryContext newCategoryContext, bool publish, PostResult postResult)
        {
            if (!publish && !Options.SupportsPostAsDraft)
            {
                //Debug.Fail("Post to draft not supported on this provider");
                throw new BlogClientPostAsDraftUnsupportedException();
            }

            Login();

            FixupBlogId(ref blogId);

            XmlDocument doc       = new XmlDocument();
            XmlElement  entryNode = doc.CreateElementNS(_atomNS.Uri, _atomNS.Prefix + ":entry");

            doc.AppendChild(entryNode);
            Populate(post, null, entryNode, publish);

            string slug = null;

            if (Options.SupportsSlug)
            {
                slug = post.Slug;
            }

            XmlRestRequestHelper.XmlRequestResult xmlResult2 = new XmlRestRequestHelper.XmlRequestResult();
            xmlResult2.uri = new Uri(blogId);
            XmlDocument result = await xmlRestRequestHelper.Post(
                new HttpAsyncRequestFilter(new NewPostRequest(this, slug).RequestFilter),
                ENTRY_CONTENT_TYPE,
                doc,
                _clientOptions.CharacterSet,
                xmlResult2);

            postResult.ETag = FilterWeakEtag(xmlResult2.responseHeaders["ETag"]);
            string location = xmlResult2.responseHeaders["Location"];

            if (string.IsNullOrEmpty(location))
            {
                throw new BlogClientInvalidServerResponseException("POST", "The HTTP response was missing the required Location header.", "");
            }
            if (location != xmlResult2.responseHeaders["Content-Location"] || result == null)
            {
                XmlRestRequestHelper.XmlRequestResult xmlResult = new XmlRestRequestHelper.XmlRequestResult();
                xmlResult.uri = new Uri(location);
                result        = await xmlRestRequestHelper.Get(RequestFilter, xmlResult);

                postResult.ETag = FilterWeakEtag(xmlResult.responseHeaders["ETag"]);
            }

            postResult.AtomRemotePost = (XmlDocument)result.CloneNode(true);
            Parse(result.DocumentElement, true, xmlResult2.uri);

            if (Options.SupportsNewCategories)
            {
                foreach (BlogPostCategory category in post.NewCategories)
                {
                    newCategoryContext.NewCategoryAdded(category);
                }
            }

            return(PostUriToPostId(location));
        }
コード例 #7
0
        /// <summary>
        /// Converts an html string into xaml string.
        /// </summary>
        /// <param name="htmlString">
        /// Input html which may be badly formatted xml.
        /// </param>
        /// <param name="asFlowDocument">
        /// true indicates that we need a FlowDocument as a root element;
        /// false means that Section or Span elements will be used
        /// dependeing on StartFragment/EndFragment comments locations.
        /// </param>
        /// <returns>
        /// Well-formed xml representing XAML equivalent for the input html string.
        /// </returns>
        public static string ConvertHtmlToXaml(string htmlString, bool asFlowDocument)
        {
            // Create well-formed Xml from Html string
            XmlElement htmlElement = HtmlParser.ParseHtml(htmlString);

            // Decide what name to use as a root
            string rootElementName = asFlowDocument ? Xaml_FlowDocument : Xaml_Section;

            // Create an XmlDocument for generated xaml
            var xamlTree = new XmlDocument();

            var xamlFlowDocumentElement = xamlTree.CreateElementNS(_xamlNamespace, rootElementName);

            // Source context is a stack of all elements - ancestors of a parentElement
            var sourceContext = new List<IXmlNode>(10);

            // Clear fragment parent
            InlineFragmentParentElement = null;

            // convert root html element
            AddBlock(xamlFlowDocumentElement, htmlElement, new Dictionary<string, string>(), sourceContext);

            // In case if the selected fragment is inline, extract it into a separate Span wrapper
            if (!asFlowDocument)
            {
                xamlFlowDocumentElement = ExtractInlineFragment(xamlFlowDocumentElement) as XmlElement;
            }

            // Return a string representing resulting Xaml
            xamlFlowDocumentElement.SetAttribute("xml:space", "preserve");

            string xaml = xamlFlowDocumentElement.GetXml();

            return xaml;
        }