本文整理汇总了C#中IXmlDocument类的典型用法代码示例。如果您正苦于以下问题:C# IXmlDocument类的具体用法?C# IXmlDocument怎么用?C# IXmlDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IXmlDocument类属于命名空间,在下文中一共展示了IXmlDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetNodeValueString
static void SetNodeValueString(string str, IXmlDocument xmldoc, IXmlNode node) {
IXmlText textNode;
int res = xmldoc.CreateTextNode(str, out textNode);
ComFunctions.CheckHRESULT(res);
IXmlNode textNodeAsNode = (IXmlNode)textNode;
IXmlNode appendedChild;
res = node.AppendChild(textNodeAsNode, out appendedChild);
ComFunctions.CheckHRESULT(res);
}
示例2: XmlDocumentLoader
public XmlDocumentLoader(IXmlDocument document)
{
if (document == null)
throw new ArgumentNullException(nameof(document));
Document = document;
XmlReaderSettings = new XmlReaderSettings();
XmlReaderSettings.DtdProcessing = DtdProcessing.Parse;
XmlWriterSettings = new XmlWriterSettings();
XmlWriterSettings.Indent = true;
}
示例3: SetImageSrc
static void SetImageSrc(IXmlDocument xmldoc, string imagePath) {
IXmlNodeList nodes;
int res = xmldoc.GetElementsByTagName("image", out nodes);
ComFunctions.CheckHRESULT(res);
IXmlNode imageNode;
res = nodes.Item(0, out imageNode);
ComFunctions.CheckHRESULT(res);
IXmlNode srcAttribute;
res = imageNode.Attributes.GetNamedItem("src", out srcAttribute);
ComFunctions.CheckHRESULT(res);
SetNodeValueString(imagePath, xmldoc, srcAttribute);
}
示例4: ParseDom
private void ParseDom(IXmlDocument dom)
{
var root = dom.DocumentElement;
if (root == null) return;
switch (root.LocalName)
{
case "score-partwise":
ParsePartwise(root);
break;
case "score-timewise":
//ParseTimewise(root);
break;
default:
throw new UnsupportedFormatException();
}
}
示例5: Save
public virtual bool Save(IXmlDocument document, Stream stream)
{
if (!stream.CanWrite)
throw new NotSupportedException("The stream cannot be written to");
try
{
var xdoc = LoadXDocument(stream);
using (var xmlWriter = XmlWriter.Create(stream, XmlWriterSettings))
{
Document.Export(xdoc);
xdoc.Save(xmlWriter);
}
return true;
}
catch (Exception ex)
{
throw;
}
}
示例6: ParseDom
private void ParseDom(IXmlDocument dom)
{
var root = dom.DocumentElement;
if (root == null) return;
// the XML uses IDs for referring elements within the
// model. Therefore we do the parsing in 2 steps:
// - at first we read all model elements and store them by ID in a lookup table
// - after that we need to join up the information.
if (root.LocalName == "GPIF")
{
Score = new Score();
// parse all children
root.IterateChildren(n =>
{
if (n.NodeType == XmlNodeType.Element)
{
switch (n.LocalName)
{
case "Score":
ParseScoreNode(n);
break;
case "MasterTrack":
ParseMasterTrackNode(n);
break;
case "Tracks":
ParseTracksNode(n);
break;
case "MasterBars":
ParseMasterBarsNode(n);
break;
case "Bars":
ParseBars(n);
break;
case "Voices":
ParseVoices(n);
break;
case "Beats":
ParseBeats(n);
break;
case "Notes":
ParseNotes(n);
break;
case "Rhythms":
ParseRhythms(n);
break;
}
}
});
}
else
{
throw new UnsupportedFormatException();
}
BuildModel();
}
示例7: CreateDocumentType
private void CreateDocumentType(JsonReader reader, IXmlDocument document, IXmlNode currentNode)
{
string name = null;
string publicId = null;
string systemId = null;
string internalSubset = null;
while (reader.Read() && reader.TokenType != JsonToken.EndObject)
{
switch (reader.Value.ToString())
{
case "@name":
reader.Read();
name = reader.Value.ToString();
break;
case "@public":
reader.Read();
publicId = reader.Value.ToString();
break;
case "@system":
reader.Read();
systemId = reader.Value.ToString();
break;
case "@internalSubset":
reader.Read();
internalSubset = reader.Value.ToString();
break;
default:
throw new JsonSerializationException("Unexpected property name encountered while deserializing XmlDeclaration: " + reader.Value);
}
}
IXmlNode documentType = document.CreateXmlDocumentType(name, publicId, systemId, internalSubset);
currentNode.AppendChild(documentType);
}
示例8: CreateElement
private IXmlElement CreateElement(string elementName, IXmlDocument document, string elementPrefix, XmlNamespaceManager manager)
{
return (!string.IsNullOrEmpty(elementPrefix))
? document.CreateElement(elementName, manager.LookupNamespace(elementPrefix))
: document.CreateElement(elementName);
}
示例9: AddAttribute
private static void AddAttribute(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string attributeName, XmlNamespaceManager manager, string attributePrefix)
{
string attributeValue = reader.Value.ToString();
IXmlNode attribute = (!string.IsNullOrEmpty(attributePrefix))
? document.CreateAttribute(attributeName, manager.LookupNamespace(attributePrefix), attributeValue)
: document.CreateAttribute(attributeName, attributeValue);
((IXmlElement) currentNode).SetAttributeNode(attribute);
}
示例10: AddJsonArrayAttribute
private void AddJsonArrayAttribute(IXmlElement element, IXmlDocument document)
{
element.SetAttributeNode(document.CreateAttribute("json:Array", JsonNamespaceUri, "true"));
}
示例11: ReadElement
private void ReadElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName, XmlNamespaceManager manager)
{
if (string.IsNullOrEmpty(propertyName))
throw new JsonSerializationException("XmlNodeConverter cannot convert JSON with an empty property name to XML.");
Dictionary<string, string> attributeNameValues = ReadAttributeElements(reader, manager);
string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);
if (propertyName.StartsWith("@"))
{
var attributeName = propertyName.Substring(1);
var attributeValue = reader.Value.ToString();
var attributePrefix = MiscellaneousUtils.GetPrefix(attributeName);
var attribute = (!string.IsNullOrEmpty(attributePrefix))
? document.CreateAttribute(attributeName, manager.LookupNamespace(attributePrefix), attributeValue)
: document.CreateAttribute(attributeName, attributeValue);
((IXmlElement)currentNode).SetAttributeNode(attribute);
}
else
{
IXmlElement element = CreateElement(propertyName, document, elementPrefix, manager);
currentNode.AppendChild(element);
// add attributes to newly created element
foreach (KeyValuePair<string, string> nameValue in attributeNameValues)
{
string attributePrefix = MiscellaneousUtils.GetPrefix(nameValue.Key);
IXmlNode attribute = (!string.IsNullOrEmpty(attributePrefix))
? document.CreateAttribute(nameValue.Key, manager.LookupNamespace(attributePrefix), nameValue.Value)
: document.CreateAttribute(nameValue.Key, nameValue.Value);
element.SetAttributeNode(attribute);
}
if (reader.TokenType == JsonToken.String
|| reader.TokenType == JsonToken.Integer
|| reader.TokenType == JsonToken.Float
|| reader.TokenType == JsonToken.Boolean
|| reader.TokenType == JsonToken.Date)
{
element.AppendChild(document.CreateTextNode(ConvertTokenToXmlValue(reader)));
}
else if (reader.TokenType == JsonToken.Null)
{
// empty element. do nothing
}
else
{
// finished element will have no children to deserialize
if (reader.TokenType != JsonToken.EndObject)
{
manager.PushScope();
DeserializeNode(reader, document, manager, element);
manager.PopScope();
}
}
}
}
示例12: ReadArrayElements
private void ReadArrayElements(JsonReader reader, IXmlDocument document, string propertyName, IXmlNode currentNode, XmlNamespaceManager manager)
{
string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);
IXmlElement nestedArrayElement = CreateElement(propertyName, document, elementPrefix, manager);
currentNode.AppendChild(nestedArrayElement);
while (reader.Read() && reader.TokenType != JsonToken.EndArray)
{
DeserializeValue(reader, document, manager, propertyName, nestedArrayElement);
}
}
示例13: ReadArrayElements
// Token: 0x060006E6 RID: 1766
// RVA: 0x000385A8 File Offset: 0x000367A8
private void ReadArrayElements(JsonReader reader, IXmlDocument document, string propertyName, IXmlNode currentNode, XmlNamespaceManager manager)
{
string prefix = MiscellaneousUtils.GetPrefix(propertyName);
IXmlElement xmlElement = this.CreateElement(propertyName, document, prefix, manager);
currentNode.AppendChild(xmlElement);
int num = 0;
while (reader.Read())
{
if (reader.TokenType == JsonToken.EndArray)
{
break;
}
this.DeserializeValue(reader, document, manager, propertyName, xmlElement);
num++;
}
if (this.WriteArrayAttribute)
{
this.AddJsonArrayAttribute(xmlElement, document);
}
if (num == 1 && this.WriteArrayAttribute)
{
IXmlElement element = Enumerable.Single<IXmlElement>(Enumerable.OfType<IXmlElement>(xmlElement.ChildNodes), (IXmlElement n) => n.LocalName == propertyName);
this.AddJsonArrayAttribute(element, document);
}
}
示例14: CreateElement
private IXmlElement CreateElement(string elementName, IXmlDocument document, string elementPrefix, XmlNamespaceManager manager)
{
string ns = string.IsNullOrEmpty(elementPrefix) ? manager.DefaultNamespace : manager.LookupNamespace(elementPrefix);
IXmlElement element = (!string.IsNullOrEmpty(ns)) ? document.CreateElement(elementName, ns) : document.CreateElement(elementName);
return element;
}
示例15: SetDuration
static void SetDuration(IXmlDocument xmldoc, NotificationDuration duration) {
IXmlNodeList nodes;
ComFunctions.CheckHRESULT(xmldoc.GetElementsByTagName("toast", out nodes));
IXmlNode toastNode;
ComFunctions.CheckHRESULT(nodes.Item(0, out toastNode));
((IXmlElement)toastNode).SetAttribute("duration", "long");
}