本文整理汇总了C#中System.Xml.XmlDocument.CreateEntityReference方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.CreateEntityReference方法的具体用法?C# XmlDocument.CreateEntityReference怎么用?C# XmlDocument.CreateEntityReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.CreateEntityReference方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChildNodes
public void ChildNodes ()
{
XmlTextReader xtr = new XmlTextReader ("<!DOCTYPE root [<!ENTITY ent 'ent-value'><!ENTITY el '<foo>hoge</foo><bar/>'>]><root/>",
XmlNodeType.Document, null);
XmlDocument doc = new XmlDocument ();
doc.Load (xtr);
XmlEntityReference ent = doc.CreateEntityReference ("ent");
// ChildNodes are not added yet.
AssertNull (ent.FirstChild);
doc.DocumentElement.AppendChild (ent);
// ChildNodes are added here.
AssertNotNull (ent.FirstChild);
ent = doc.CreateEntityReference ("foo");
AssertNull (ent.FirstChild);
// Entity value is empty when the matching DTD entity
// node does not exist.
doc.DocumentElement.AppendChild (ent);
AssertNotNull (ent.FirstChild);
AssertEquals (String.Empty, ent.FirstChild.Value);
ent = doc.CreateEntityReference ("el");
AssertEquals ("", ent.InnerText);
doc.DocumentElement.AppendChild (ent);
AssertEquals ("<foo>hoge</foo><bar />", ent.InnerXml);
AssertEquals ("hoge", ent.InnerText);
AssertEquals (XmlNodeType.Element, ent.FirstChild.NodeType);
}
示例2: WriteTo
public void WriteTo ()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<root/>");
XmlEntityReference er = doc.CreateEntityReference("foo");
doc.DocumentElement.AppendChild(er);
AssertEquals ("Name", "foo", er.Name);
AssertEquals ("WriteTo", "<root>&foo;</root>", doc.DocumentElement.OuterXml);
}
示例3: WriteStyle
private void WriteStyle(XmlDocument doc, XmlElement me, object o)
{
if (o.GetType() != typeof(SvgStyle))
{
me.SetAttribute("style", doc.NamespaceURI, o.ToString());
return;
}
SvgStyle style = (SvgStyle)o;
/*
foreach(string s in style.Keys)
{
me.SetAttribute(s, doc.NamespaceURI, style.Get(s).ToString());
}
*/
me.SetAttribute("style", doc.NamespaceURI, style.ToString());
doc.CreateEntityReference("pingu");
}
示例4: RecCompXML
/// <summary>
/// Used by CompressXML
/// </summary>
/// <param name="counts">Map of attribute to number of occurrences -- could be used to improve algorithm</param>
/// <param name="entities">Map of attribute to entity name</param>
/// <param name="doc"></param>
/// <param name="el"></param>
/// <param name="idx">Number that is incremented to provide new entity names</param>
private static void RecCompXML(Hashtable counts, Hashtable entities, XmlDocument doc, XmlElement el, ref int idx)
{
ArrayList keys = new ArrayList();
foreach(XmlAttribute att in el.Attributes)
{
//don't try to do anything with xmlns nodes.
if (att.Name.IndexOf("xmlns") == -1)
keys.Add(att.Name);
}
foreach(string s in keys)
{
string val = el.Attributes[s].Value;
if (counts[val] == null)
{
counts[val] = 1;
}
else
{
counts[val] = (int)counts[val] + 1;
}
if (val.Length > 30)
{
string entname;
if(entities[val] == null)
{
idx += 1;
entname = "E"+idx.ToString();
entities[val] = entname;
}
else
{
entname = (string)entities[val];
}
XmlAttribute attr;
//xlinks are a special case at the moment as the .NET XML API requires whatever bit of code
//outputs a qualified name to *just magically happen to know* the URI that the prefix refers to.
if (s.IndexOf("xlink") == 0)
{
attr = doc.CreateAttribute(s, "http://www.w3.org/1999/xlink");
}
else
{
attr = doc.CreateAttribute(s);
}
attr.AppendChild(doc.CreateEntityReference(entname));
el.SetAttributeNode(attr);
}
}
foreach(XmlNode ch in el.ChildNodes)
{
if (ch.GetType() == typeof(XmlElement))
RecCompXML(counts, entities, doc, (XmlElement)ch, ref idx);
}
}
示例5: Associate
protected internal override void Associate(XmlDocument/*!*/ document)
{
if (!IsAssociated)
{
XmlEntityReference = document.CreateEntityReference(_name);
}
}
示例6: CopyNode
void CopyNode (XmlDocument newDoc, XmlNode from, XmlNode toParent) {
if (RemoveAll && from.NodeType != XmlNodeType.Element)
return;
XmlNode child = null;
bool newLineNode = false;
switch (from.NodeType) {
case XmlNodeType.Element:
newLineNode = true;
if (RemoveNamespacesAndPrefixes)
child = newDoc.CreateElement (from.LocalName);
else {
XmlElement e = from as XmlElement;
child = newDoc.CreateElement (e.Prefix, e.LocalName, e.NamespaceURI);
}
break;
case XmlNodeType.Attribute: {
if (RemoveAttributes)
return;
XmlAttribute fromAttr = from as XmlAttribute;
if (!fromAttr.Specified)
return;
XmlAttribute a;
if (RemoveNamespacesAndPrefixes)
a = newDoc.CreateAttribute (fromAttr.LocalName);
else
a = newDoc.CreateAttribute (fromAttr.Prefix, fromAttr.LocalName, fromAttr.NamespaceURI);
toParent.Attributes.Append(a);
CopyNodes (newDoc, from, a);
return;
}
case XmlNodeType.CDATA:
newLineNode = true;
child = newDoc.CreateCDataSection ((from as XmlCDataSection).Data);
break;
case XmlNodeType.Comment:
if (RemoveWhiteSpace)
return;
newLineNode = true;
child = newDoc.CreateComment ((from as XmlComment).Data);
break;
case XmlNodeType.ProcessingInstruction:
newLineNode = true;
XmlProcessingInstruction pi = from as XmlProcessingInstruction;
child = newDoc.CreateProcessingInstruction (pi.Target, pi.Data);
break;
case XmlNodeType.DocumentType:
newLineNode = true;
toParent.AppendChild (from.CloneNode (true));
return;
case XmlNodeType.EntityReference:
child = newDoc.CreateEntityReference ((from as XmlEntityReference).Name);
break;
case XmlNodeType.SignificantWhitespace:
if (RemoveWhiteSpace)
return;
child = newDoc.CreateSignificantWhitespace (from.Value);
break;
case XmlNodeType.Text:
if (RemoveText)
return;
newLineNode = true;
child = newDoc.CreateTextNode (from.Value);
break;
case XmlNodeType.Whitespace:
if (RemoveWhiteSpace)
return;
child = newDoc.CreateWhitespace (from.Value);
break;
case XmlNodeType.XmlDeclaration:
newLineNode = true;
XmlDeclaration d = from as XmlDeclaration;
XmlDeclaration d1 = newDoc.CreateXmlDeclaration (d.Version, d.Encoding, d.Standalone);
newDoc.InsertBefore(d1, newDoc.DocumentElement);
return;
}
if (NewLines && newLineNode && toParent.NodeType != XmlNodeType.Attribute) {
XmlSignificantWhitespace s = newDoc.CreateSignificantWhitespace("\r\n");
toParent.AppendChild (s);
}
toParent.AppendChild(child);
CopyNodes (newDoc, from, child);
}
示例7: RecCompXML
/// <summary>
/// Used by CompressXML
/// </summary>
/// <param name="counts">Map of attribute to number of occurrences -- could be used to improve algorithm</param>
/// <param name="entities">Map of attribute to entity name</param>
/// <param name="doc"></param>
/// <param name="el"></param>
/// <param name="idx">Number that is incremented to provide new entity names</param>
private static void RecCompXML(Hashtable counts, Hashtable entities, XmlDocument doc, XmlElement el, ref int idx)
{
ArrayList keys = new ArrayList();
foreach(XmlAttribute att in el.Attributes)
{
keys.Add(att.Name);
}
foreach(string s in keys)
{
string val = el.Attributes[s].Value;
if (counts[val] == null)
{
counts[val] = 1;
}
else
{
counts[val] = (int)counts[val] + 1;
}
if (val.Length > 30)
{
string entname;
if(entities[val] == null)
{
idx += 1;
entname = "E"+idx.ToString();
entities[val] = entname;
}
else
{
entname = (string)entities[val];
}
XmlAttribute attr = doc.CreateAttribute(s);
attr.AppendChild(doc.CreateEntityReference(entname));
el.SetAttributeNode(attr);
}
}
foreach(XmlNode ch in el.ChildNodes)
{
if (ch.GetType() == typeof(XmlElement))
RecCompXML(counts, entities, doc, (XmlElement)ch, ref idx);
}
}