void RegressionTest1() { // Make sure we can do MoveToElement after reading multiple attributes. SgmlReader r = new SgmlReader(); r.InputStream = new StringReader("<test id='10' x='20'><a/><!--comment-->test</test>"); if (r.Read()) { while (r.MoveToNextAttribute()) { Trace.WriteLine(r.Name); } if (r.MoveToElement()) { Trace.WriteLine(r.ReadInnerXml()); } } }
public void Test_MoveToNextAttribute() { // Make sure we can do MoveToElement after reading multiple attributes. var r = new SgmlReader { InputStream = new StringReader("<test id='10' x='20'><a/><!--comment-->test</test>") }; Assert.IsTrue(r.Read()); while(r.MoveToNextAttribute()) { _log.Debug(r.Name); } if(r.MoveToElement()) { _log.Debug(r.ReadInnerXml()); } }
void Debug(SgmlReader sr) { NodeTypeFlags[] AllowedContentMap = new NodeTypeFlags[19] { NodeTypeFlags.None, // none NodeTypeFlags.Element | NodeTypeFlags.Attribute | NodeTypeFlags.Text | NodeTypeFlags.CDATA | NodeTypeFlags.EntityReference | NodeTypeFlags.ProcessingInstruction | NodeTypeFlags.Comment | NodeTypeFlags.Whitespace | NodeTypeFlags.SignificantWhitespace | NodeTypeFlags.EndElement, // element NodeTypeFlags.Text | NodeTypeFlags.EntityReference, // attribute NodeTypeFlags.None, // text NodeTypeFlags.None, // cdata NodeTypeFlags.None, // entity reference NodeTypeFlags.None, // entity NodeTypeFlags.None, // processing instruction NodeTypeFlags.None, // comment NodeTypeFlags.Comment | NodeTypeFlags.DocumentType | NodeTypeFlags.Element | NodeTypeFlags.EndElement | NodeTypeFlags.ProcessingInstruction | NodeTypeFlags.Whitespace | NodeTypeFlags.SignificantWhitespace | NodeTypeFlags.XmlDeclaration, // document NodeTypeFlags.None, // document type NodeTypeFlags.None, // document fragment (not expecting these) NodeTypeFlags.None, // notation NodeTypeFlags.None, // whitespace NodeTypeFlags.None, // signification whitespace NodeTypeFlags.None, // end element NodeTypeFlags.None, // end entity NodeTypeFlags.None, // filler NodeTypeFlags.None, // xml declaration. }; Stack s = new Stack(); while (sr.Read()) { if (sr.NodeType == XmlNodeType.EndElement) { s.Pop(); } if (s.Count > 0) { XmlNodeType pt = (XmlNodeType)s.Peek(); NodeTypeFlags p = NodeTypeMap[(int)pt]; NodeTypeFlags f = NodeTypeMap[(int)sr.NodeType]; if ((AllowedContentMap[(int)pt]& f) != f) { Console.WriteLine("Invalid content!!"); } } if (s.Count != sr.Depth-1) { Console.WriteLine("Depth is wrong!"); } if ( (sr.NodeType == XmlNodeType.Element && !sr.IsEmptyElement) || sr.NodeType == XmlNodeType.Document) { s.Push(sr.NodeType); } for (int i = 1; i < sr.Depth; i++) Console.Write(" "); Console.Write(sr.NodeType.ToString() + " " + sr.Name); if (sr.NodeType == XmlNodeType.Element && sr.AttributeCount > 0) { sr.MoveToAttribute(0); Console.Write(" (" + sr.Name+"="+sr.Value + ")"); sr.MoveToElement(); } if (sr.Value != null) { Console.Write(" " + sr.Value.Replace("\n"," ").Replace("\r","")); } Console.WriteLine(); } }