public static void Main()
  {
    XmlNodeReader reader = null;

    try
    {
       //Create and load an XML document.
       XmlDocument doc = new XmlDocument();
       doc.LoadXml("<!DOCTYPE book [<!ENTITY h 'harcover'>]>" +
                   "<book genre='novel' misc='sale-item &h; 1987'>" +
                   "</book>");
        
       //Create the reader. 
       reader = new XmlNodeReader(doc);

       //Read the misc attribute. The attribute is parsed into multiple 
       //text and entity reference nodes.
       reader.MoveToContent();
       reader.MoveToAttribute("misc");
       while (reader.ReadAttributeValue()){
          if (reader.NodeType==XmlNodeType.EntityReference)
            //To expand the entity, call ResolveEntity.
            Console.WriteLine("{0} {1}", reader.NodeType, reader.Name);
          else
             Console.WriteLine("{0} {1}", reader.NodeType, reader.Value);
        } 
     } 
     finally 
     {
        if (reader != null)
          reader.Close();
      }
  }
Exemple #2
0
        public void NodeReaderReadAttributeValueWithSimpleXml()
        {
            string        xml        = "<root><child /></root>";
            XmlNodeReader nodeReader = NodeReaderTestHelper.CreateNodeReader(xml);

            Assert.True(nodeReader.Read());
            Assert.False(nodeReader.ReadAttributeValue());
        }
Exemple #3
0
        public void NodeReaderReadAttributeValueWithEmptyXml()
        {
            var document   = new XmlDocument();
            var nodeReader = new XmlNodeReader(document);

            Assert.False(nodeReader.ReadAttributeValue());
            Assert.False(nodeReader.HasValue);
            Assert.Equal(string.Empty, nodeReader.Value);
        }
Exemple #4
0
 public override bool ReadAttributeValue()
 {
     if (IsXmlDataNode)
     {
         return(_xmlNodeReader.ReadAttributeValue());
     }
     Fx.Assert("ExtensionDataReader ReadAttributeValue method should only be called for IXmlSerializable");
     return(false);
 }
        [Test]         // bug #550379
        public void MoveToNextAttributeFromValue()
        {
            document.LoadXml("<ul test='xxx'></ul>");
            XmlNodeReader nr = new XmlNodeReader(document);

            nr.Read();
            nr.Read();
            Assert.IsTrue(nr.MoveToFirstAttribute(), "#1");
            Assert.IsTrue(nr.ReadAttributeValue(), "#2");
            Assert.IsFalse(nr.MoveToNextAttribute(), "#3");
        }
Exemple #6
0
        public void NodeReaderReadAttributeValueWithAttributeXml()
        {
            string        xml        = "<root attr='val'><child /></root>";
            XmlNodeReader nodeReader = NodeReaderTestHelper.CreateNodeReader(xml);

            Assert.True(nodeReader.Read());
            Assert.Equal("root", nodeReader.Name);
            Assert.True(nodeReader.MoveToAttribute("attr"));
            Assert.True(nodeReader.ReadAttributeValue());
            Assert.Equal(ReadState.Interactive, nodeReader.ReadState);
            Assert.Equal(XmlNodeType.Text, nodeReader.NodeType);
            Assert.Equal(2, nodeReader.Depth);
            Assert.True(nodeReader.HasValue);
            Assert.Equal("val", nodeReader.Value);
            Assert.Equal(1, nodeReader.AttributeCount);
        }