本文整理汇总了C#中System.Xml.XmlDocument.CreateDocumentFragment方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.CreateDocumentFragment方法的具体用法?C# XmlDocument.CreateDocumentFragment怎么用?C# XmlDocument.CreateDocumentFragment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.CreateDocumentFragment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static TwoTransparent2 Create()
{
TwoTransparent2 ttxf = new TwoTransparent2();
XmlDocument doc = new XmlDocument();
ttxf._frag = doc.CreateDocumentFragment();
ttxf._frag2 = doc.CreateDocumentFragment();
ttxf._frag2.AppendChild( doc.CreateElement( "sub2" ) ).InnerText = "3";
ttxf._frag2.AppendChild( doc.CreateElement( "sub2" ) ).InnerText = "4";
return ttxf;
}
示例2: Create2
public static TwoTransparentXmlFragments Create2()
{
TwoTransparentXmlFragments ttxf = new TwoTransparentXmlFragments();
ttxf.elem1 = null;
ttxf.elem3 = null;
XmlDocument doc = new XmlDocument();
ttxf._frag = doc.CreateDocumentFragment();
ttxf._frag2 = doc.CreateDocumentFragment();
ttxf._frag2.AppendChild( doc.CreateElement( "sub2" ) ).InnerText = "3";
ttxf._frag2.AppendChild( doc.CreateElement( "sub2" ) ).InnerText = "4";
return ttxf;
}
示例3: CheckNodeType
public static void CheckNodeType()
{
var xmlDocument = new XmlDocument();
var documentFragment = xmlDocument.CreateDocumentFragment();
Assert.Equal(XmlNodeType.DocumentFragment, documentFragment.NodeType);
}
示例4: AddHeaderInformation
public static void AddHeaderInformation(XmlDocument xmlDoc, QMaker qMaker)
{
StringBuilder sbH = new StringBuilder();
StringWriter tempWriterH = new StringWriter(sbH);
XmlTextWriter writerH = new XmlTextWriter(tempWriterH);
writerH.WriteStartElement("Headers");
foreach (QField gField in qMaker.Groups)
{
writerH.WriteStartElement("Header");
writerH.WriteAttributeString("Name", gField.Name);
writerH.WriteAttributeString("Description", gField.FriendlyName);
writerH.WriteEndElement();//Header
}
foreach (QField fField in qMaker.Fields)
{
writerH.WriteStartElement("Header");
writerH.WriteAttributeString("Name", fField.Name);
writerH.WriteAttributeString("Description", fField.FriendlyName);
writerH.WriteEndElement();//Header
}
writerH.WriteEndElement();//Headers
writerH.Flush();
XmlDocumentFragment xmlHeaders = xmlDoc.CreateDocumentFragment();
xmlHeaders.InnerXml = sbH.ToString();
xmlDoc.SelectSingleNode("Report").AppendChild(xmlHeaders);
}
示例5: Filter
/// <summary>
/// Replaces the read-only Word content controls with XWiki macro markup.
/// </summary>
/// <param name="xmlDoc">A reference to the xml document instance.</param>
public void Filter(ref XmlDocument xmlDoc)
{
XmlNodeList macroNodes = xmlDoc.GetElementsByTagName("Sdt", "urn:schemas-microsoft-com:office:word");
XmlDocumentFragment docFrag = xmlDoc.CreateDocumentFragment();
Dictionary<String, String> macros = this.manager.States.Macros;
//We use a new list because the XmlNodeList will break when operationg with its' elements.
List<XmlNode> nodeList = new List<XmlNode>();
foreach (XmlNode node in macroNodes)
{
nodeList.Add(node);
}
foreach (XmlNode node in nodeList)
{
try
{
String id = node.Attributes["ID"].Value;
if (macros.ContainsKey(id))
{
String content = macros[id];
docFrag.InnerXml = content;
node.ParentNode.ReplaceChild(docFrag, node);
}
}
catch (NullReferenceException nre)
{
Log.Exception(nre);
}
catch (Exception ex)
{
Log.Exception(ex);
}
}
}
示例6: GetAttributesOnDocumentFragment
public static void GetAttributesOnDocumentFragment()
{
var xmlDocument = new XmlDocument();
var documentFragment = xmlDocument.CreateDocumentFragment();
Assert.Null(documentFragment.Attributes);
}
示例7: Constructor
public void Constructor ()
{
XmlDocument d = new XmlDocument ();
XmlDocumentFragment df = d.CreateDocumentFragment ();
AssertEquals ("#Constructor.NodeName", "#document-fragment", df.Name);
AssertEquals ("#Constructor.NodeType", XmlNodeType.DocumentFragment, df.NodeType);
}
示例8: GetResponse
public ControlResponse GetResponse(Exception ex)
{
var env = new XmlDocument();
env.AppendChild(env.CreateXmlDeclaration("1.0", "utf-8", "yes"));
var envelope = env.CreateElement("SOAP-ENV", "Envelope", NS_SOAPENV);
env.AppendChild(envelope);
envelope.SetAttribute("encodingStyle", NS_SOAPENV, "http://schemas.xmlsoap.org/soap/encoding/");
var rbody = env.CreateElement("SOAP-ENV:Body", NS_SOAPENV);
env.DocumentElement.AppendChild(rbody);
var fault = env.CreateElement("SOAP-ENV", "Fault", NS_SOAPENV);
var faultCode = env.CreateElement("faultcode");
faultCode.InnerText = "500";
fault.AppendChild(faultCode);
var faultString = env.CreateElement("faultstring");
faultString.InnerText = ex.ToString();
fault.AppendChild(faultString);
var detail = env.CreateDocumentFragment();
detail.InnerXml = "<detail><UPnPError xmlns=\"urn:schemas-upnp-org:control-1-0\"><errorCode>401</errorCode><errorDescription>Invalid Action</errorDescription></UPnPError></detail>";
fault.AppendChild(detail);
rbody.AppendChild(fault);
return new ControlResponse
{
Xml = env.OuterXml,
IsSuccessful = false
};
}
示例9: SerializeAsXmlNode
public XmlNode SerializeAsXmlNode(XmlDocument doc)
{
System.IO.MemoryStream ms = new MemoryStream();
XmlSerializer serializer = new XmlSerializer(typeof(ColumnCollection));
XmlTextReader xRead = null;
XmlNode xTable = null;
try
{
xTable = doc.CreateNode(XmlNodeType.Element, "TABLE", doc.NamespaceURI);
serializer.Serialize(ms, this);
ms.Position = 0;
xRead = new XmlTextReader( ms );
xRead.MoveToContent();
string test = xRead.ReadInnerXml();
XmlDocumentFragment docFrag = doc.CreateDocumentFragment();
docFrag.InnerXml = test;
xTable.AppendChild(docFrag);
}
catch(Exception ex)
{
throw new Exception("IdentityCollection Serialization Error.", ex);
}
finally
{
ms.Close();
if (xRead != null) xRead.Close();
}
return xTable;
}
示例10: Add
void Add(XmlDocument docFrom,XmlDocument docTo,string id/*,string text*/)
{
XmlNodeList nodeList = docFrom.SelectNodes("root/tablename[@ID='"+id+"']");
string [] text = new string[nodeList.Count];
foreach(XmlNode curNode in nodeList)
{
string curText = curNode.Attributes["Text"].Value;
Match match = Regex.Match(curText,"\\\\\\d+$");
int index = 0;
if(match.Success) index = int.Parse(match.Value.Substring(1));
text[index] = curText;
docFrom.DocumentElement.RemoveChild(curNode);
}
XmlDocumentFragment docFrag = docTo.CreateDocumentFragment();
XmlNode parentNode = docFrag;
foreach(string str in text)
{
XmlElement newNode = docTo.CreateElement("treenode");
newNode.SetAttribute("text",str);
parentNode.AppendChild(newNode);
parentNode = newNode;
}
docTo.DocumentElement.AppendChild(docFrag);
}
示例11: XmlNodeWriter
// It should be public after some tests are done :-)
public XmlNodeWriter (bool isDocumentEntity)
{
doc = new XmlDocument ();
state = XmlNodeType.None;
this.isDocumentEntity = isDocumentEntity;
if (!isDocumentEntity)
current = fragment = doc.CreateDocumentFragment ();
}
示例12: ToXml
public static XmlNode ToXml(this string xml)
{
var doc = new XmlDocument();
var fragment = doc.CreateDocumentFragment();
fragment.InnerXml = xml;
doc.AppendChild(fragment);
return doc.FirstChild;
}
示例13: TransparentXmlFragment
public TransparentXmlFragment( bool init )
{
elem1 = "3";
elem3 = "4";
XmlDocument doc = new XmlDocument();
_frag = doc.CreateDocumentFragment();
XmlNode node = _frag.AppendChild( doc.CreateElement( "sub1" ) );
node.AppendChild( doc.CreateElement( "extra" ) );
_frag.AppendChild( doc.CreateElement( "sub2" ) ).InnerText = "2";
}
示例14: SetInnerXml
public void SetInnerXml ()
{
document = new XmlDocument ();
fragment = document.CreateDocumentFragment ();
fragment.InnerXml = "<foo /><bar><child /></bar><baz />";
AssertEquals ("foo", fragment.FirstChild.Name);
AssertEquals ("bar", fragment.FirstChild.NextSibling.Name);
AssertEquals ("child", fragment.FirstChild.NextSibling.FirstChild.Name);
AssertEquals ("baz", fragment.LastChild.Name);
}
示例15: OnDocumentFragment
public static void OnDocumentFragment()
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml("<root><child1/>some text<child2/><child3/></root>");
var documentFragment = xmlDocument.CreateDocumentFragment();
documentFragment.AppendChild(xmlDocument.DocumentElement);
Assert.Null(documentFragment.NextSibling);
}