/// <summary> /// This method gets called when an end tag is encountered. /// </summary> /// <param name="uri"></param> /// <param name="lname"></param> /// <param name="name">the name of the tag that ends</param> public override void EndElement(string uri, string lname, string name) { if (MyTags.ContainsKey(name)) { XmlPeer peer = (XmlPeer)MyTags[name]; HandleEndingTags(peer.Tag); } else { HandleEndingTags(name); } }
/// <summary> /// This method gets called when a start tag is encountered. /// </summary> /// <param name="uri">the Uniform Resource Identifier</param> /// <param name="lname">the local name (without prefix), or the empty string if Namespace processing is not being performed.</param> /// <param name="name">the name of the tag that is encountered</param> public override void EndElement(string uri, string lname, string name) { //System.err.Println("End: " + name); name = name.ToLowerInvariant(); if (ElementTags.PARAGRAPH.Equals(name)) { Document.Add((IElement)Stack.Pop()); return; } if (HtmlTagMap.IsHead(name)) { // we do nothing return; } if (HtmlTagMap.IsTitle(name)) { if (CurrentChunk != null) { _bodyAttributes.Add(ElementTags.TITLE, CurrentChunk.Content); } return; } if (HtmlTagMap.IsMeta(name)) { // we do nothing return; } if (HtmlTagMap.IsLink(name)) { // we do nothing return; } if (HtmlTagMap.IsBody(name)) { // we do nothing return; } if (MyTags.ContainsKey(name)) { var peer = (XmlPeer)MyTags[name]; if (ElementTags.TABLE.Equals(peer.Tag)) { _tableBorder = false; } HandleEndingTags(peer.Tag); return; } // super.handleEndingTags is replaced with handleEndingTags // suggestion by Ken Auer HandleEndingTags(name); }
/// <summary> /// This method gets called when a start tag is encountered. /// </summary> /// <param name="uri"></param> /// <param name="lname"></param> /// <param name="name">the name of the tag that is encountered</param> /// <param name="attrs">the list of attributes</param> public override void StartElement(string uri, string lname, string name, Hashtable attrs) { if (MyTags.ContainsKey(name)) { XmlPeer peer = (XmlPeer)MyTags[name]; HandleStartingTags(peer.Tag, peer.GetAttributes(attrs)); } else { Properties attributes = new Properties(); if (attrs != null) { foreach (string key in attrs.Keys) { attributes.Add(key, (string)attrs[key]); } } HandleStartingTags(name, attributes); } }
public override void StartElement(string uri, string lname, string name, Hashtable attrs) { //System.err.Println("Start: " + name); // super.handleStartingTags is replaced with handleStartingTags // suggestion by Vu Ngoc Tan/Hop name = name.ToLowerInvariant(); if (HtmlTagMap.IsHtml(name)) { // we do nothing return; } if (HtmlTagMap.IsHead(name)) { // we do nothing return; } if (HtmlTagMap.IsTitle(name)) { // we do nothing return; } if (HtmlTagMap.IsMeta(name)) { // we look if we can change the body attributes string meta = null; string content = null; if (attrs != null) { foreach (string attribute in attrs.Keys) { if (Util.EqualsIgnoreCase(attribute, HtmlTags.CONTENT)) { content = (string)attrs[attribute]; } else if (Util.EqualsIgnoreCase(attribute, HtmlTags.NAME)) { meta = (string)attrs[attribute]; } } } if (meta != null && content != null) { _bodyAttributes.Add(meta, content); } return; } if (HtmlTagMap.IsLink(name)) { // we do nothing for the moment, in a later version we could extract the style sheet return; } if (HtmlTagMap.IsBody(name)) { // maybe we could extract some info about the document: color, margins,... // but that's for a later version... var peer = new XmlPeer(ElementTags.ITEXT, name); peer.AddAlias(ElementTags.TOP, HtmlTags.TOPMARGIN); peer.AddAlias(ElementTags.BOTTOM, HtmlTags.BOTTOMMARGIN); peer.AddAlias(ElementTags.RIGHT, HtmlTags.RIGHTMARGIN); peer.AddAlias(ElementTags.LEFT, HtmlTags.LEFTMARGIN); _bodyAttributes.AddAll(peer.GetAttributes(attrs)); HandleStartingTags(peer.Tag, _bodyAttributes); return; } if (MyTags.ContainsKey(name)) { var peer = (XmlPeer)MyTags[name]; if (ElementTags.TABLE.Equals(peer.Tag) || ElementTags.CELL.Equals(peer.Tag)) { var p = peer.GetAttributes(attrs); string value; if (ElementTags.TABLE.Equals(peer.Tag) && (value = p[ElementTags.BORDERWIDTH]) != null) { if (float.Parse(value, NumberFormatInfo.InvariantInfo) > 0) { _tableBorder = true; } } if (_tableBorder) { p.Add(ElementTags.LEFT, "true"); p.Add(ElementTags.RIGHT, "true"); p.Add(ElementTags.TOP, "true"); p.Add(ElementTags.BOTTOM, "true"); } HandleStartingTags(peer.Tag, p); return; } HandleStartingTags(peer.Tag, peer.GetAttributes(attrs)); return; } var attributes = new Properties(); if (attrs != null) { foreach (string attribute in attrs.Keys) { attributes.Add(attribute.ToLowerInvariant(), ((string)attrs[attribute]).ToLowerInvariant()); } } HandleStartingTags(name, attributes); }