Inheritance: XmlNodeBase
示例#1
0
 protected override void AddNode(INode node, bool named, Action <INode> modify)
 {
     if (node is ElementNode)
     {
         Element.Add(((ElementNode)node).Element);
     }
     else if (node is AttributeNode)
     {
         Element.Add(((AttributeNode)node).Attribute);
     }
     else if (!named)
     {
         throw new UnnamedChildrenNotSupportedException();
     }
     else
     {
         var         @namespace = GetNamespace(node.Name, node.Metadata, _namespace, Options);
         XmlNodeBase xmlNode;
         if ((Options.Serialization.XmlValueNodeType == XmlValueNodeType.Attribute ||
              node.Metadata.Contains <System.Xml.Serialization.XmlAttributeAttribute>() ||
              node.Metadata.Contains <XmlAttributeAttribute>()) &&
             node.NodeType.IsValue())
         {
             xmlNode = new AttributeNode(Element.CreateAttribute(node.Name), this, Options);
         }
         else if (node.Metadata.Contains <XmlSiblingsAttribute>())
         {
             xmlNode = this;
         }
         else
         {
             xmlNode = new ElementNode(Element.CreateElement(GetNodeName(
                                                                 node.Name, @namespace)), Options, @namespace, this);
             node.Metadata.GetAll <WithAttributeAttribute>().ForEach(x =>
                                                                     xmlNode.Element.Add(new XAttribute(x.Name, x.Value)));
         }
         xmlNode.Configure(modify);
     }
 }
示例#2
0
 public void should_insert_xml_attribute()
 {
     var parent = ElementNode.Create("Oh", Metadata.Empty, Options);
     var node = new AttributeNode(new XAttribute("Hai", "yada"), (ElementNode)parent, Options);
     parent.ShouldNotExecuteCallback<INode>((s, c) => s.Add(node, c));
     var child = parent.Cast<AttributeNode>().First();
     child.Attribute.Name.ShouldEqual(node.Attribute.Name);
     child.Attribute.Value.ShouldEqual(node.Attribute.Value);
     child.Parent.ShouldBeSameAs(parent);
 }
示例#3
0
 public void Setup()
 {
     _parent = new ElementNode(new XElement("yada"), null);
     _attribute = new AttributeNode(new XDocument(new XElement("Yada",
         new XAttribute("Oh", "Hai"))).Root.Attribute("Oh"), _parent, Options.Create());
 }