本文整理匯總了C#中Windows.Data.Xml.Dom.XmlDocument.CreateElementNS方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlDocument.CreateElementNS方法的具體用法?C# XmlDocument.CreateElementNS怎麽用?C# XmlDocument.CreateElementNS使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Windows.Data.Xml.Dom.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.CreateElementNS方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ConvertHtmlToXaml
/// <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;
}
示例2: ConvertHtmlToXaml
/// <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;
}