public virtual void Check(Lexer lexer, Node node) { AttVal type = node.GetAttrByName("type"); node.CheckUniqueAttributes(lexer); if (type == null) { Report.AttrError(lexer, node, "type", Report.MISSING_ATTRIBUTE); node.AddAttribute("type", "text/css"); } }
private static Node ImportXML(XmlReader reader) { do { if (reader.NodeType == XmlNodeType.Element) { break; } } while (reader.Read()); if (reader.NodeType != XmlNodeType.Element) { throw new Exception("here needs a element begin!"); } Node node = new Node(); node.Key = reader.Name; node.Value = reader.Value; if (reader.HasAttributes) { for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); node.AddAttribute(new Node(reader.Value, reader.Name)); } reader.MoveToElement(); } if (!reader.IsEmptyElement) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { node.AddChild(ImportXML(reader)); } else if (reader.NodeType == XmlNodeType.EndElement) { break; } } } return(node); }
public virtual void Check(Lexer lexer, Node node) { AttVal rel = node.GetAttrByName("rel"); node.CheckUniqueAttributes(lexer); if (rel != null && rel.Val != null && rel.Val.Equals("stylesheet")) { AttVal type = node.GetAttrByName("type"); if (type == null) { Report.AttrError(lexer, node, "type", Report.MISSING_ATTRIBUTE); node.AddAttribute("type", "text/css"); } } }
public void ToNode(XmlTextReader reader, int level, bool comment) { Node child; // essentially: in the loop, add new nodes to this.childNodes while (reader.Read()) { //IO.WriteLine ("Read name={0} value={1} reader.NodeType={2} Level={3}", reader.Name, reader.Value.Trim (), reader.NodeType, level); switch (reader.NodeType) { case XmlNodeType.Element: // create a new subelement bool isEmpty = reader.IsEmptyElement; child = new Node(); child.type = XmlNodeType.Element; child.name = reader.LocalName; child.text = reader.Prefix; while (reader.MoveToNextAttribute()) { child.AddAttribute(reader.Name, reader.Value); } if (isEmpty) { childNodes.Insert(0, child); continue; } child.ToNode(reader, level + 1, comment); childNodes.Insert(0, child); break; case XmlNodeType.Attribute: this.AddAttribute(reader.Name, reader.Value); break; case XmlNodeType.EndElement: return; case XmlNodeType.Comment: if (comment) { goto case XmlNodeType.Text; } break; case XmlNodeType.Text: case XmlNodeType.CDATA: case XmlNodeType.SignificantWhitespace: case XmlNodeType.Whitespace: child = new Node(); child.type = reader.NodeType; child.Text = reader.Value; childNodes.Insert(0, child); break; case XmlNodeType.ProcessingInstruction: child = new Node(); child.type = reader.NodeType; child.name = reader.Name; child.text = reader.Value; childNodes.Insert(0, child); break; case XmlNodeType.XmlDeclaration: while (reader.MoveToNextAttribute()) { this.AddAttribute(reader.Name, reader.Value); } break; case XmlNodeType.Document: case XmlNodeType.DocumentFragment: case XmlNodeType.DocumentType: case XmlNodeType.EndEntity: case XmlNodeType.Entity: case XmlNodeType.EntityReference: case XmlNodeType.None: case XmlNodeType.Notation: // ignore break; default: throw new ApplicationException( string.Format("*** Unhandled XmlTextReader.NodeType: {0}", reader.NodeType)); } } return; }
public virtual void Check(Lexer lexer, Node node) { AttVal attval; bool hasAlt = false; bool hasSrc = false; bool hasUseMap = false; bool hasIsMap = false; bool hasDataFld = false; node.CheckUniqueAttributes(lexer); for (attval = node.Attributes; attval != null; attval = attval.Next) { Attribute attribute = attval.CheckAttribute(lexer, node); if (attribute == AttributeTable.AttrAlt) { hasAlt = true; } else if (attribute == AttributeTable.AttrSrc) { hasSrc = true; } else if (attribute == AttributeTable.AttrUsemap) { hasUseMap = true; } else if (attribute == AttributeTable.AttrIsmap) { hasIsMap = true; } else if (attribute == AttributeTable.AttrDatafld) { hasDataFld = true; } else if (attribute == AttributeTable.AttrWidth || attribute == AttributeTable.AttrHeight) { lexer.Versions &= ~ HtmlVersion.Html20; } } if (!hasAlt) { lexer.BadAccess |= Report.MISSING_IMAGE_ALT; Report.AttrError(lexer, node, "alt", Report.MISSING_ATTRIBUTE); if (lexer.Options.AltText != null) { node.AddAttribute("alt", lexer.Options.AltText); } } if (!hasSrc && !hasDataFld) { Report.AttrError(lexer, node, "src", Report.MISSING_ATTRIBUTE); } if (hasIsMap && !hasUseMap) { Report.AttrError(lexer, node, "ismap", Report.MISSING_IMAGEMAP); } }
public virtual void Check(Lexer lexer, Node node) { AttVal attval; bool hasAlt = false; bool hasSrc = false; bool hasUseMap = false; bool hasIsMap = false; bool hasDataFld = false; node.CheckUniqueAttributes(lexer); for (attval = node.Attributes; attval != null; attval = attval.Next) { Attribute attribute = attval.CheckAttribute(lexer, node); if (attribute == AttributeTable.AttrAlt) { hasAlt = true; } else if (attribute == AttributeTable.AttrSrc) { hasSrc = true; } else if (attribute == AttributeTable.AttrUsemap) { hasUseMap = true; } else if (attribute == AttributeTable.AttrIsmap) { hasIsMap = true; } else if (attribute == AttributeTable.AttrDatafld) { hasDataFld = true; } else if (attribute == AttributeTable.AttrWidth || attribute == AttributeTable.AttrHeight) { lexer.Versions &= ~HtmlVersion.Html20; } } if (!hasAlt) { lexer.BadAccess |= Report.MISSING_IMAGE_ALT; Report.AttrError(lexer, node, "alt", Report.MISSING_ATTRIBUTE); if (lexer.Options.AltText != null) { node.AddAttribute("alt", lexer.Options.AltText); } } if (!hasSrc && !hasDataFld) { Report.AttrError(lexer, node, "src", Report.MISSING_ATTRIBUTE); } if (hasIsMap && !hasUseMap) { Report.AttrError(lexer, node, "ismap", Report.MISSING_IMAGEMAP); } }