本文整理汇总了C#中IXmlDocument.CreateAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# IXmlDocument.CreateAttribute方法的具体用法?C# IXmlDocument.CreateAttribute怎么用?C# IXmlDocument.CreateAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IXmlDocument
的用法示例。
在下文中一共展示了IXmlDocument.CreateAttribute方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
}
}
示例2: AddJsonArrayAttribute
private void AddJsonArrayAttribute(IXmlElement element, IXmlDocument document)
{
element.SetAttributeNode(document.CreateAttribute("json:Array", JsonNamespaceUri, "true"));
#if !NET20
// linq to xml doesn't automatically include prefixes via the namespace manager
if (element is XElementWrapper)
{
if (element.GetPrefixOfNamespace(JsonNamespaceUri) == null)
{
element.SetAttributeNode(document.CreateAttribute("xmlns:json", "http://www.w3.org/2000/xmlns/", JsonNamespaceUri));
}
}
#endif
}
示例3: 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);
}
示例4: AddJsonArrayAttribute
private void AddJsonArrayAttribute(IXmlElement element, IXmlDocument document)
{
element.SetAttributeNode(document.CreateAttribute("json:Array", JsonNamespaceUri, "true"));
}
示例5: ReadElement
private void ReadElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName, XmlNamespaceManager manager)
{
Dictionary<string, string> attributeNameValues = ReadAttributeElements(reader, manager);
string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);
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)
{
element.AppendChild(document.CreateTextNode(reader.Value.ToString()));
}
else if (reader.TokenType == JsonToken.Integer)
{
element.AppendChild(document.CreateTextNode(XmlConvert.ToString((long)reader.Value)));
}
else if (reader.TokenType == JsonToken.Float)
{
element.AppendChild(document.CreateTextNode(XmlConvert.ToString((double)reader.Value)));
}
else if (reader.TokenType == JsonToken.Boolean)
{
element.AppendChild(document.CreateTextNode(XmlConvert.ToString((bool)reader.Value)));
}
else if (reader.TokenType == JsonToken.Date)
{
DateTime d = (DateTime)reader.Value;
element.AppendChild(document.CreateTextNode(XmlConvert.ToString(d, DateTimeUtils.ToSerializationMode(d.Kind))));
}
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();
}
}
}
示例6: CreateElement
private void CreateElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string elementName, XmlNamespaceManager manager, string elementPrefix, Dictionary<string, string> attributeNameValues)
{
IXmlElement element = CreateElement(elementName, 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) ?? string.Empty, 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();
}
manager.RemoveNamespace(string.Empty, manager.DefaultNamespace);
}
}
示例7: AddAttribute
private static void AddAttribute(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName, string attributeName, XmlNamespaceManager manager, string attributePrefix)
{
if (currentNode.NodeType == XmlNodeType.Document)
{
throw JsonSerializationException.Create(reader, "JSON root object has property '{0}' that will be converted to an attribute. A root object cannot have any attribute properties. Consider specifing a DeserializeRootElementName.".FormatWith(CultureInfo.InvariantCulture, propertyName));
}
string encodedName = XmlConvert.EncodeName(attributeName);
string attributeValue = reader.Value.ToString();
IXmlNode attribute = (!string.IsNullOrEmpty(attributePrefix))
? document.CreateAttribute(encodedName, manager.LookupNamespace(attributePrefix), attributeValue)
: document.CreateAttribute(encodedName, attributeValue);
((IXmlElement)currentNode).SetAttributeNode(attribute);
}
示例8: ReadElement
// Token: 0x060006E4 RID: 1764
// RVA: 0x000382C8 File Offset: 0x000364C8
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> dictionary = this.ReadAttributeElements(reader, manager);
string prefix = MiscellaneousUtils.GetPrefix(propertyName);
if (StringUtils.StartsWith(propertyName, '@'))
{
string text = propertyName.Substring(1);
string value = reader.Value.ToString();
string prefix2 = MiscellaneousUtils.GetPrefix(text);
IXmlNode attributeNode = (!string.IsNullOrEmpty(prefix2)) ? document.CreateAttribute(text, manager.LookupNamespace(prefix2), value) : document.CreateAttribute(text, value);
((IXmlElement)currentNode).SetAttributeNode(attributeNode);
return;
}
IXmlElement xmlElement = this.CreateElement(propertyName, document, prefix, manager);
currentNode.AppendChild(xmlElement);
foreach (KeyValuePair<string, string> current in dictionary)
{
string prefix3 = MiscellaneousUtils.GetPrefix(current.Key);
IXmlNode attributeNode2 = (!string.IsNullOrEmpty(prefix3)) ? document.CreateAttribute(current.Key, manager.LookupNamespace(prefix3), current.Value) : document.CreateAttribute(current.Key, current.Value);
xmlElement.SetAttributeNode(attributeNode2);
}
if (reader.TokenType != JsonToken.String && reader.TokenType != JsonToken.Integer && reader.TokenType != JsonToken.Float && reader.TokenType != JsonToken.Boolean)
{
if (reader.TokenType != JsonToken.Date)
{
if (reader.TokenType == JsonToken.Null)
{
return;
}
if (reader.TokenType != JsonToken.EndObject)
{
manager.PushScope();
this.DeserializeNode(reader, document, manager, xmlElement);
manager.PopScope();
}
manager.RemoveNamespace(string.Empty, manager.DefaultNamespace);
return;
}
}
xmlElement.AppendChild(document.CreateTextNode(this.ConvertTokenToXmlValue(reader)));
}
示例9: AddJsonArrayAttribute
// Token: 0x060006E7 RID: 1767
// RVA: 0x00009E6B File Offset: 0x0000806B
private void AddJsonArrayAttribute(IXmlElement element, IXmlDocument document)
{
element.SetAttributeNode(document.CreateAttribute("json:Array", "http://james.newtonking.com/projects/json", "true"));
}
示例10: 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> dictionary = this.ReadAttributeElements(reader, manager);
string prefix1 = MiscellaneousUtils.GetPrefix(propertyName);
if (propertyName.StartsWith("@"))
{
string str1 = propertyName.Substring(1);
string str2 = reader.Value.ToString();
string prefix2 = MiscellaneousUtils.GetPrefix(str1);
IXmlNode attribute = !string.IsNullOrEmpty(prefix2) ? document.CreateAttribute(str1, manager.LookupNamespace(prefix2), str2) : document.CreateAttribute(str1, str2);
((IXmlElement) currentNode).SetAttributeNode(attribute);
}
else
{
IXmlElement element = this.CreateElement(propertyName, document, prefix1, manager);
currentNode.AppendChild((IXmlNode) element);
foreach (KeyValuePair<string, string> keyValuePair in dictionary)
{
string prefix2 = MiscellaneousUtils.GetPrefix(keyValuePair.Key);
IXmlNode attribute = !string.IsNullOrEmpty(prefix2) ? document.CreateAttribute(keyValuePair.Key, manager.LookupNamespace(prefix2), keyValuePair.Value) : document.CreateAttribute(keyValuePair.Key, keyValuePair.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(this.ConvertTokenToXmlValue(reader)));
}
else
{
if (reader.TokenType == JsonToken.Null || reader.TokenType == JsonToken.EndObject)
return;
manager.PushScope();
this.DeserializeNode(reader, document, manager, (IXmlNode) element);
manager.PopScope();
}
}
}
示例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.");
var attributeNameValues = ReadAttributeElements(reader, manager);
var 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
{
var element = CreateElement(propertyName, document, elementPrefix, manager);
currentNode.AppendChild(element);
// add attributes to newly created element
foreach (var nameValue in attributeNameValues)
{
var attributePrefix = MiscellaneousUtils.GetPrefix(nameValue.Key);
var attribute = (!string.IsNullOrEmpty(attributePrefix)) ? document.CreateAttribute(nameValue.Key, manager.LookupNamespace(attributePrefix) ?? string.Empty, nameValue.Value) : document.CreateAttribute(nameValue.Key, nameValue.Value);
element.SetAttributeNode(attribute);
}
switch (reader.TokenType)
{
case JsonToken.Date:
case JsonToken.Boolean:
case JsonToken.Float:
case JsonToken.Integer:
case JsonToken.String:
element.AppendChild(document.CreateTextNode(ConvertTokenToXmlValue(reader)));
break;
case JsonToken.Null:
break;
default:
if (reader.TokenType != JsonToken.EndObject)
{
manager.PushScope();
DeserializeNode(reader, document, manager, element);
manager.PopScope();
}
manager.RemoveNamespace(string.Empty, manager.DefaultNamespace);
break;
}
}
}