Read() public method

Reads the next node from the stream.
public Read ( ) : bool
return bool
コード例 #1
1
ファイル: SgmlUtil.cs プロジェクト: Cabana/CMSConverter
        // Creates XmlDocument from html content and return it with rootitem "<root>".
        public static XmlDocument ParseHtml(string sContent)
        {
            StringReader sr = new StringReader("<root>" + sContent + "</root>");
            SgmlReader reader = new SgmlReader();
            reader.WhitespaceHandling = WhitespaceHandling.All;
            reader.CaseFolding = Sgml.CaseFolding.ToLower;
            reader.InputStream = sr;

            StringWriter sw = new StringWriter();
            XmlTextWriter w = new XmlTextWriter(sw);
            w.Formatting = Formatting.Indented;
            w.WriteStartDocument();
            reader.Read();
            while (!reader.EOF)
            {
                w.WriteNode(reader, true);
            }
            w.Flush();
            w.Close();

            sw.Flush();

            // create document
            XmlDocument doc = new XmlDocument();
            doc.PreserveWhitespace = true;
            doc.XmlResolver = null;
            doc.LoadXml(sw.ToString());

            reader.Close();

            return doc;
        }
コード例 #2
1
ファイル: HttpUtil.cs プロジェクト: drzo/opensim4opencog
 public static string GetWellFormedHTML(string html, string xpathNavPath)
 {
     // StreamReader sReader = null;
     StringWriter sw = null;
     SgmlReader reader = null;
     XmlTextWriter writer = null;
     try
     {
         //  if (uri == String.Empty) uri = "http://www.XMLforASP.NET";
         // HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
         //  HttpWebResponse res = (HttpWebResponse)req.GetResponse();
         //  sReader = new StreamReader(res.GetResponseStream());
         reader = new SgmlReader();
         reader.DocType = "HTML";
         reader.InputStream = new StringReader(html);
         sw = new StringWriter();
         writer = new XmlTextWriter(sw);
         writer.Formatting = Formatting.Indented;
         //writer.WriteStartElement("Test");
         while (reader.Read())
         {
             if (reader.NodeType != XmlNodeType.Whitespace)
             {
                 writer.WriteNode(reader, true);
             }
         }
         //writer.WriteEndElement();
         if (xpathNavPath == null)
         {
             string sr = sw.ToString();
             sr = sr.Replace("\r", "\n");
             sr = sr.Replace("\n\n", "\n");
             return sr;
         }
         else
         { //Filter out nodes from HTML
             StringBuilder sb = new StringBuilder();
             XPathDocument doc = new XPathDocument(new StringReader(sw.ToString()));
             XPathNavigator nav = doc.CreateNavigator();
             XPathNodeIterator nodes = nav.Select(xpathNavPath);
             while (nodes.MoveNext())
             {
                 sb.Append(nodes.Current.Value + "\n");
             }
             string sr = sb.ToString();
             sr = sr.Replace("\r", "\n");
             sr = sr.Replace("\n\n", "\n");
             return sr;
         }
     }
     catch (Exception exp)
     {
         writer.Close();
         reader.Close();
         sw.Close();
         // sReader.Close();
         return exp.Message;
     }
 }
コード例 #3
0
        internal static ImageInfo[] FindImgs(
            string htmlCode)
        {
            var r =
                new SgmlReader
                    {
                        DocType = @"HTML",
                        InputStream = new StringReader(htmlCode)
                    };
            var al = new List<ImageInfo>();

            //find <img src=""
            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.Element)
                {
                    if (string.Compare(r.Name, @"img", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        if (r.HasAttributes)
                        {
                            var ii = new ImageInfo();

                            while (r.MoveToNextAttribute())
                            {
                                switch (r.Name.ToLowerInvariant())
                                {
                                    case @"src":
                                        ii.Source = r.Value;
                                        break;
                                    case @"width":
                                        ii.Width = ConvertHelper.ToInt32(r.Value);
                                        break;
                                    case @"height":
                                        ii.Height = ConvertHelper.ToInt32(r.Value);
                                        break;
                                }
                            }

                            // --

                            if (!string.IsNullOrEmpty(ii.Source))
                            {
                                al.Add(ii);
                            }
                        }
                    }
                }
            }

            return al.ToArray();
        }
コード例 #4
0
ファイル: Test.cs プロジェクト: panuganti/nreadability
        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();
            }
        }
コード例 #5
0
ファイル: HtmlHelper.cs プロジェクト: ayende/Subtext
        /// <summary>
        /// Converts the specified html into XHTML compliant text.
        /// </summary>
        /// <param name="reader">sgml reader.</param>
        /// <param name="html">html to convert.</param>
        /// <param name="converter">The converter.</param>
        /// <returns></returns>
        /// ///
        private static string ConvertHtmlToXHtml(SgmlReader reader, string html, Converter<string, string> converter)
        {
            reader.DocType = "html";
            reader.WhitespaceHandling = WhitespaceHandling.All;
            // Hack to fix SF bug #1678030
            html = RemoveNewLineBeforeCDATA(html);
            reader.InputStream = new StringReader("<html>" + html + "</html>");
            reader.CaseFolding = CaseFolding.ToLower;
            StringWriter writer = new StringWriter();
            XmlWriter xmlWriter = null;
            try
            {
                xmlWriter = new XmlTextWriter(writer);

                bool insideAnchor = false;
                bool skipRead = false;
                while ((skipRead || reader.Read()) && !reader.EOF)
                {
                    skipRead = false;
                    switch(reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            //Special case for anchor tags for the time being.
                            //We need some way to communicate which elements the current node is nested within
                            if (reader.IsEmptyElement)
                            {
                                xmlWriter.WriteStartElement(reader.LocalName);
                                xmlWriter.WriteAttributes(reader, true);
                                if (reader.LocalName == "a" || reader.LocalName == "script")
                                    xmlWriter.WriteFullEndElement();
                                else
                                    xmlWriter.WriteEndElement();
                            }
                            else
                            {
                                if (reader.LocalName == "a")
                                    insideAnchor = true;
                                xmlWriter.WriteStartElement(reader.LocalName);
                                xmlWriter.WriteAttributes(reader, true);
                            }
                            break;

                        case XmlNodeType.Text:
                            string text = reader.Value;

                            if (converter != null && !insideAnchor)
                                xmlWriter.WriteRaw(converter(text));
                            else
                                xmlWriter.WriteString(text);
                            break;

                        case XmlNodeType.EndElement:
                            if (reader.LocalName == "a")
                                insideAnchor = false;

                            if (reader.LocalName == "a" || reader.LocalName == "script")
                                xmlWriter.WriteFullEndElement();
                            else
                                xmlWriter.WriteEndElement();
                            break;

                        default:
                            xmlWriter.WriteNode(reader, true);
                            skipRead = true;
                            break;
                    }
                }
            }
            finally
            {
                if (xmlWriter != null)
                {
                    xmlWriter.Close();
                }
            }

            string xml = writer.ToString();
            return xml.Substring("<html>".Length, xml.Length - "<html></html>".Length);
        }
コード例 #6
0
ファイル: HtmlHelper.cs プロジェクト: rsaladrigas/Subtext
        public static IEnumerable<string> GetAttributeValues(this string html, string tagName, string attributeName)
        {
            var reader = new SgmlReader
            {
                DocType = "html",
                WhitespaceHandling = WhitespaceHandling.All,
                InputStream = new StringReader(string.Format("<html>{0}</html>", html))
            };

            while (reader.Read() && !reader.EOF)
            {
                if (reader.NodeType == XmlNodeType.Element && reader.LocalName == tagName)
                {
                    yield return reader.GetAttribute(attributeName);
                }
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: wheeliemow/RaccoonBlog
		private static string ConvertCommentToMarkdown(string body)
		{
			var sb = new StringBuilder();

			var sgmlReader = new SgmlReader
				{
					InputStream = new StringReader(body),
					DocType = "HTML",
					WhitespaceHandling = WhitespaceHandling.Significant,
					CaseFolding = CaseFolding.ToLower
				};

			bool outputEndElement = false;
			int indentLevel = 0;
			while (sgmlReader.Read())
			{
				switch (sgmlReader.NodeType)
				{
					case XmlNodeType.Text:
						if (indentLevel > 0)
							sb.Append("\t");
						sb.AppendLine(sgmlReader.Value);
						break;
					case XmlNodeType.Element:
						switch (sgmlReader.LocalName)
						{
							case "h1":
								sb.Append("## ");
								break;
							case "br":
								sb.AppendLine("  ");
								break;
							case "a":
								if (sgmlReader.MoveToAttribute("href"))
								{
									string url = sgmlReader.Value;
									sgmlReader.Read();

									sb.AppendFormat("[{0}]({1})", sgmlReader.Value, url);
								}
								break;
							case "html":
								break;
							case "strong":
							case "b":
								sb.AppendFormat("**{0}**", sgmlReader.Value);
								break;
							case "i":
							case "em":
								sb.AppendFormat("_{0}_", sgmlReader.Value);
								break;
							case "li":
								sb.AppendFormat("- {0}", sgmlReader.Value);
								break;
							case "pre":
							case "code":
							case "quote":
								indentLevel = 1;
								break;
							case "ul":
							case "ol":
							case "img":
								break;
							default:
								outputEndElement = true;
								sb.Append("<").Append(sgmlReader.LocalName);
								break;
						}
						break;
					case XmlNodeType.SignificantWhitespace:
					case XmlNodeType.Whitespace:
					case XmlNodeType.CDATA:
						break;
					case XmlNodeType.EndElement:
						indentLevel = 0;
						if (outputEndElement)
							sb.Append(">");
						outputEndElement = false;
						break;
					default:
						throw new ArgumentOutOfRangeException();
				}
			}

			return sb.ToString();
		}
コード例 #8
0
ファイル: CodeSnippet.cs プロジェクト: supermuk/iudico
        public static string TransformHtmlToXHTML(string inputHtml)
        {
            var sgmlReader = new SgmlReader { DocType = "HTML",  };
            var stringReader = new StringReader(inputHtml);
            sgmlReader.InputStream = stringReader;

            var stringWriter = new StringWriter();

            using (var xmlWriter = new XmlTextWriter(stringWriter))
            {
                sgmlReader.Read();

                while (!sgmlReader.EOF)
                {
                    xmlWriter.WriteNode(sgmlReader, true);
                }
            }
            return RemoveCopyOfImage(stringWriter.ToString());
        }
コード例 #9
0
ファイル: Main.cs プロジェクト: panuganti/nreadability
        void Process(SgmlReader reader, string uri)
        {
            if (uri == null) {
                reader.InputStream = Console.In;
            } else {
                reader.Href = uri;
            }

            if (this.encoding == null) {
                this.encoding = reader.GetEncoding();
            }

            XmlTextWriter w = null;
            if (output != null) {
                w = new XmlTextWriter(output, this.encoding);
            }
            else {
                w = new XmlTextWriter(Console.Out);
            }
            if (formatted) w.Formatting = Formatting.Indented;
            if (!noxmldecl) {
                w.WriteStartDocument();
            }
            reader.Read();
            while (!reader.EOF) {
                w.WriteNode(reader, true);
            }
            w.Flush();
            w.Close();
        }
コード例 #10
0
ファイル: Test.cs プロジェクト: panuganti/nreadability
        void RunTest(SgmlReader reader, int line, string args, string input, string expectedOutput)
        {
            try {
                bool testdoc = false;
                bool testclone = false;
                bool format = true;
                bool ignore = false;
                foreach(string arg in args.Split(' ')) {
                    string sarg = arg.Trim();
                    if(sarg.Length == 0)
                        continue;
                    if(sarg[0] == '-') {
                        switch(sarg.Substring(1)) {
                        case "html":
                            reader.DocType = "html";
                            break;
                        case "lower":
                            reader.CaseFolding = CaseFolding.ToLower;
                            break;
                        case "upper":
                            reader.CaseFolding = CaseFolding.ToUpper;
                            break;
                        case "testdoc":
                            testdoc = true;
                            break;
                        case "testclone":
                            testclone = true;
                            break;
                        case "noformat":
                            format = false;
                            break;
                        case "ignore":
                            ignore = true;
                            break;
                        }
                    }
                }
                this.tests++;
                if(ignore) {
                    this.ignored++;
                    return;
                }
                reader.InputStream = new StringReader(input);
                if(format) {
                    reader.WhitespaceHandling = WhitespaceHandling.None;
                } else {
                    reader.WhitespaceHandling = WhitespaceHandling.All;
                }
                StringWriter output = new StringWriter();
                XmlTextWriter w = new XmlTextWriter(output);
                if(format) {
                    w.Formatting = Formatting.Indented;
                }
                if(testdoc) {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(reader);
                    doc.WriteTo(w);
                } else if(testclone) {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(reader);
                    XmlNode clone = doc.Clone();
                    clone.WriteTo(w);
                } else {
                    reader.Read();
                    while(!reader.EOF) {
                        w.WriteNode(reader, true);
                    }
                }
                w.Close();
                string actualOutput = output.ToString();

                // validate output
                using(StringReader source = new StringReader(actualOutput)) {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(source);
                }

                // compare output
                if(actualOutput.Trim().Replace("\r", "") != expectedOutput.Trim().Replace("\r", "")) {
                    Console.WriteLine();
                    Console.WriteLine("ERROR: Test failed on line {0}", line);
                    Console.WriteLine("---- Expected output");
                    Console.Write(expectedOutput);
                    Console.WriteLine("---- Actual output");
                    Console.WriteLine(actualOutput);
                } else {
                    this.passed++;
                }
            } catch(Exception e) {
                Console.WriteLine("FATAL ERROR: Test threw an exception on line {0}", line);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.ToString());
                Console.WriteLine("---- Input");
                Console.Write(input);
            }
        }
コード例 #11
0
ファイル: Test.cs プロジェクト: dblock/dblog
 void RunTest(SgmlReader reader, int line, string args, string input, string expectedOutput)
 {
     bool testdoc = false;
     foreach (string arg in args.Split(' ')){
         string sarg = arg.Trim();
         if (sarg.Length==0) continue;
         if (sarg[0] == '-'){
             switch (sarg.Substring(1)){
                 case "html":
                     reader.DocType = "html";
                     break;
                 case "lower":
                     reader.CaseFolding = CaseFolding.ToLower;
                     break;
                 case "upper":
                     reader.CaseFolding = CaseFolding.ToUpper;
                     break;
                 case "testdoc":
                     testdoc = true;
                     break;
             }
         }
     }
     this.tests++;
     reader.InputStream = new StringReader(input);
     reader.WhitespaceHandling = WhitespaceHandling.None;
     StringWriter output = new StringWriter();
     XmlTextWriter w = new XmlTextWriter(output);
     w.Formatting = Formatting.Indented;
     if (testdoc) {
         XmlDocument doc = new XmlDocument();
         doc.Load(reader);
         doc.WriteTo(w);
     } else {
         reader.Read();
         while (!reader.EOF) {
             w.WriteNode(reader, true);
         }
     }
     w.Close();
     string actualOutput = output.ToString();
     if (actualOutput.Trim() != expectedOutput.Trim()) {
         Console.WriteLine("ERROR: Test failed on line {0}", line);
         Console.WriteLine("---- Expected output");
         Console.WriteLine(expectedOutput);
         Console.WriteLine("---- Actual output");
         Console.WriteLine(actualOutput);
     } else {
         this.passed++;
     }
 }
コード例 #12
0
ファイル: HtmlRenderer.cs プロジェクト: davelondon/dontstayin
		public void LoadHtml(string rawHtml)
		{
			if (rawHtml.StartsWith("<dsi:html"))
			{
				//parse and remove dsi:html tag...
				string tag = rawHtml.Substring(0, rawHtml.IndexOf('>') + 1) + "</dsi:html>";
				rawHtml = rawHtml.Substring(rawHtml.IndexOf('>') + 1);
				rawHtml = rawHtml.Substring(0, rawHtml.Length - 11);

				/*
				<dsi:html 
					formatting = [true | false] // do we convert line-breaks to br tags?
					container = [true | false]  // do we render the html in a container div?
					></dsi:html>
				*/

				SgmlReader sgml = new SgmlReader();
				sgml.InputStream = new StringReader(tag);
				sgml.DocType = "HTML";
				sgml.Read();

				if (sgml.GetAttribute("formatting") != null)
					Formatting = bool.Parse(sgml.GetAttribute("formatting"));

				if (sgml.GetAttribute("container") != null)
					Container = bool.Parse(sgml.GetAttribute("container"));

			}

			this.rawHtml = rawHtml;
		}
コード例 #13
0
ファイル: HtmlRenderer.cs プロジェクト: davelondon/dontstayin
		public string dsiTagReplacement(Match m)
		{
			string tagName = "dsi";
			try
			{
				//string[] arrParts = m.Groups[1].Value.Split[" "];
				//Dictionary<string, string> parts = new Dictionary<string, string>();
				SgmlReader sgml = new SgmlReader();
				string inStr = m.Groups[0].Value;
				if (inStr.StartsWith("<dsi:link"))
					inStr += "</dsi:link>";
				sgml.InputStream = new StringReader(inStr);
				sgml.DocType = "HTML";
				sgml.Read();

				tagName = sgml.Name;
				string uniqueId = Guid.NewGuid().ToString("N");

				#region Parse attributes
				Dictionary<string, string> attributes = new Dictionary<string, string>();
				while (sgml.MoveToNextAttribute())
				{
					attributes.Add(sgml.Name.ToLower(), sgml.Value);
				}
				#endregion

				string typeAtt = attributes.ContainsKey("type") ? attributes["type"] : null;
				string refAtt = attributes.ContainsKey("ref") ? attributes["ref"] : null;

				#region Parse styles
				Dictionary<string, string> style = new Dictionary<string, string>();
				if (attributes.ContainsKey("style"))
				{
					foreach (string s in attributes["style"].Split(';'))
					{
						try
						{
							if (s.Contains(":"))
								style[s.Split(':')[0].Trim()] = s.Split(':')[1].Trim();
						}
						catch
						{
						}
					}
				}
				#endregion

				#region Parse class
				List<string> classes = new List<string>();
				if (attributes.ContainsKey("class"))
				{
					foreach (string s in attributes["class"].Split(' '))
					{
						try
						{
							classes.Add(s);
						}
						catch
						{
						}
					}
				}
				#endregion

				if (tagName == "dsi:video")
				{
					#region dsi:video
					/*
					<dsi:video 
						type = [dsi | flv | youtube | google | metacafe | myspace | break | collegehumor | redtube | ebaumsworld | dailymotion] 
						ref = [dsi-photo-k | site-ref]
						src = [flv-url]
						width = [width] (optional)
						height = [height] (optional)
						nsfw = [true | false] (optional)
						/> 
					*/
					bool nsfw = attributes.ContainsKey("nsfw") ? bool.Parse(attributes["nsfw"].ToLower()) : false;
					string draw = attributes.ContainsKey("draw") ? attributes["draw"].ToLower() : "auto";
					if (typeAtt == "youtube")
					{
						#region youtube
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 425;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 355;

						//<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/8VtWo8tFdPQ&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/8VtWo8tFdPQ&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://www.youtube.com/v/" + refAtt + "&rel=1");
						#endregion
					}
					else if (typeAtt == "metacafe")
					{
						#region metacafe
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 400;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 345;

						//<embed src="http://www.metacafe.com/fplayer/1029494/how_to_make_fire_balls.swf" width="400" height="345" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"> </embed><br><font size = 1><a href="http://www.metacafe.com/watch/1029494/how_to_make_fire_balls/">How To Make Fire Balls</a> - <a href="http://www.metacafe.com/">The funniest videos clips are here</a></font>
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://www.metacafe.com/fplayer/" + refAtt + ".swf");
						#endregion
					}
					else if (typeAtt == "google")
					{
						#region google
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 400;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 326;

						//<embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=-7477616603879486362&hl=en-GB" flashvars=""> </embed>
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://video.google.com/googleplayer.swf?docId=" + refAtt + "&hl=en-GB");
						#endregion
					}
					else if (typeAtt == "flv")
					{
						#region flv
						string flvUrl = attributes.ContainsKey("src") ? attributes["src"] : null;
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 450;
						int height = attributes.ContainsKey("height") ? (int.Parse(attributes["height"]) + 20) : 357;

						return GetFlash(uniqueId, height, width, nsfw, draw, "/misc/flvplayer.swf", "file", flvUrl, "autoStart", "0");
						#endregion
					}
					else if (typeAtt == "dsi")
					{
						#region dsi
						try
						{
							Photo p = new Photo(int.Parse(refAtt));
							if (p.MediaType != Photo.MediaTypes.Video)
							{
								return "[Invalid ref " + refAtt + " - this is not a video]";
							}
							else
							{
								if (p.ContentDisabled)
								{
									return "[Invalid ref " + refAtt + " - video disabled]";
								}
								else
								{
									if (p.Status == Photo.StatusEnum.Enabled)
									{
										//int width = p.VideoMedWidth;
										//int height = p.VideoMedHeight + 20;

										int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : p.VideoMedWidth;
										int height = attributes.ContainsKey("height") ? (int.Parse(attributes["height"]) + 20) : (p.VideoMedHeight + 20);

										return GetFlash(uniqueId, height, width, nsfw, draw, "/misc/flvplayer.swf", "file", p.VideoMedPath, "autoStart", "0", "jpg", p.WebPath);
									}
									else if (p.Status == Photo.StatusEnum.Moderate)
									{
										return "[Invalid ref " + refAtt + " - video waiting for moderation]";
									}
									else if (p.Status == Photo.StatusEnum.Processing)
									{
										return "[Invalid ref " + refAtt + " - video still processing]";
									}
								}
							}
						}
						catch
						{
							return "[Invalid ref " + refAtt + " - video not found]";
						}
						return "[Invalid ref " + refAtt + " - error]";
						#endregion
					}
					else if (typeAtt == "collegehumor")
					{
						#region collegehumor
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 450;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 337;

						//<object type="application/x-shockwave-flash" data="http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=1754304&fullscreen=1" width="480" height="360" ><param name="allowfullscreen" value="true" /><param name="movie" quality="best" value="http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=1754304&fullscreen=1" /></object>
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=" + refAtt + "&fullscreen=1");
						#endregion
					}
					else if (typeAtt == "myspace")
					{
						#region myspace
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 430;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 346;

						//<embed src="http://lads.myspace.com/videos/vplayer.swf" flashvars="m=25330587&v=2&type=video" type="application/x-shockwave-flash" width="430" height="346"></embed>
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://lads.myspace.com/videos/vplayer.swf", "m", refAtt, "v", "2", "type", "video");
						#endregion
					}
					else if (typeAtt == "break")
					{
						#region break
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 464;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 392;

						//<object width="464" height="392"><param name="movie" value="http://embed.break.com/NDMyNjg3"></param><embed src="http://embed.break.com/NDMyNjg3" type="application/x-shockwave-flash" width="464" height="392"></embed></object>
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://embed.break.com/" + refAtt);
						#endregion
					}
					else if (typeAtt == "redtube")
					{
						#region redtube
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 434;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 344;

						//<object height="344" width="434"><param name="movie" value="http://embed.redtube.com/player/"><param name="FlashVars" value="id=2394&style=redtube"><embed src="http://embed.redtube.com/player/?id=2394&style=redtube" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" height="344" width="434"></object>
						return GetFlash(uniqueId, height, width, true, draw, "http://embed.redtube.com/player/?id=" + refAtt + "&style=redtube", "id", refAtt, "style", "redtube");
						#endregion
					}
					else if (typeAtt == "ebaumsworld")
					{
						#region ebaumsworld
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 425;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 345;

						//<embed src="http://www.ebaumsworld.com/mediaplayer.swf" flashvars="file=http://media.ebaumsworld.com/2008/01/trouble-leaving-parking-lot.flv&displayheight=321&image=http://media.ebaumsworld.com/2008/01/trouble-leaving-parking-lot.jpg" loop="false" menu="false" quality="high" bgcolor="#ffffff" width="425" height="345" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://www.ebaumsworld.com/mediaplayer.swf", "file", "http://media.ebaumsworld.com/" + refAtt + ".flv", "displayheight", (height - 24).ToString(), "image", "http://media.ebaumsworld.com/" + refAtt + ".jpg");
						#endregion
					}
					else if (typeAtt == "dailymotion")
					{
						#region dailymotion
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 420;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 331;

						//<div><object width="420" height="331"><param name="movie" value="http://www.dailymotion.com/swf/x3xmzx"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.dailymotion.com/swf/x3xmzx" type="application/x-shockwave-flash" width="420" height="331" allowFullScreen="true" allowScriptAccess="always"></embed></object><br /><b><a href="http://www.dailymotion.com/video/x3xmzx_time-attack-evo-crash-knockhill-200_auto">TIME ATTACK EVO CRASH KNOCKHILL 2007</a></b><br /><i>Uploaded by <a href="http://www.dailymotion.com/TIMEATTACKTV">TIMEATTACKTV</a></i></div>
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://www.dailymotion.com/swf/" + refAtt);
						#endregion
					}
					else if (typeAtt == "veoh")
					{
						return "[Veoh videos disabled]";
						#region veoh
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 450;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 365;

						//<embed src="http://www.veoh.com/videodetails2.swf?player=videodetailsembedded&type=v&permalinkId=v1644215kQ3H8PG2&id=anonymous" allowFullScreen="true" width="540" height="438" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed><br/><a href="http://www.veoh.com/">Online Videos by Veoh.com</a>
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://www.veoh.com/videodetails2.swf?player=videodetailsembedded&type=v&permalinkId=" + refAtt + "&id=anonymous");
						#endregion
					}
					else
					{
						return "[Invalid type attribute]";
					}
					#endregion
				}
				else if (tagName == "dsi:audio")
				{
					#region dsi:audio
					/*
					<dsi:audio 
						type = [mp3]
						src = [mp3-url]
						nsfw = [true | false] (optional)
					/>
					*/
					if (typeAtt == "mp3")
					{
						#region mp3
						string mp3Url = attributes.ContainsKey("src") ? attributes["src"] : null;
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 290;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 24;

						string audioPlayerSwfPath = Storage.Path(new Guid("7abb3119-f8ad-43ff-be01-764b2ae111fc"), "swf", Storage.Stores.Pix);

						return GetFlash(uniqueId, height, width, false, "load", audioPlayerSwfPath, "soundFile", mp3Url, "autoStart", "no") +
								@"<a href=""" + mp3Url + @"""><img src=""/gfx/download-button2.png"" width=""73"" height=""16"" border=""0"" /></a>";
						#endregion
					}
					else
					{
						return "[Invalid type attribute]";
					}
					#endregion
				}
				else if (tagName == "dsi:flash")
				{
					#region dsi:flash
					/*
					<dsi:flash 
						src = [swf-url]
						width = [width] 
						height = [height]
						nsfw = [true | false] (optional)
						play = [true | false] (optional)
						loop = [true | false] (optional)
						menu = [true | false] (optional)
						quality = [low | autolow | autohigh | medium | high | best] (optional)
						scale = [default | noorder | exactfit] (optional)
						align = [l | t | r | b] (optional)
						salign = [l | t | r | b | tl | tr | bl | br] (optional)
						wmode = [window | opaque | transparent] (optional)
						bgcolor = [colour] (optional)
						base = [base-url] (optional)
						flashvars = [flashvars] (optional)
						/>
					*/
					string swfUrl = attributes.ContainsKey("src") ? attributes["src"] : null;
					return getFlashAttributesFromSgml(uniqueId, swfUrl, attributes);
					#endregion
				}
				else if (tagName == "dsi:quote")
				{
					#region dsi:quote
					Usr u = null;
					try
					{
						u = new Usr(int.Parse(refAtt));
					}
					catch { }

					if (u != null)
					{
						StringBuilder sb = new StringBuilder();
						sb.Append("<div class=\"QuoteName\">");
						sb.Append(u.Link());
						sb.Append(" said:");
						sb.Append("</div>");
						sb.Append("<div class=\"QuoteBody\">");
						return sb.ToString();
					}
					else
					{
						return "<div class=\"QuoteBody\">";
					}
					#endregion
				}
				else if (tagName == "dsi:object" || tagName == "dsi:link")
				{
					#region dsi:object, dsi:link
					/*
					<dsi:object
						type = [usr | event | venue | place | group | brand | photo | misc]
						ref = [object-k]
						style = [
							content: {text* | icon | text-under-icon};   // for type=usr, event, venue, place, group, brand
							details: {none* | venue | place | country};  // for type=event, venue, place
							date: {false* | true};                       // for type=event
							snip: {number};                              // for type=event
							rollover: {true* | false}                    // for type=usr, photo
							photo: {icon* | thumb | web}                 // for type=photo
							link: {true* | false}
						]
					/>
					*/

					string app = attributes.ContainsKey("app") ? (attributes["app"] == "home" ? null : attributes["app"]) : null;
					string date = attributes.ContainsKey("date") ? attributes["date"].Replace('-', '/') : null;
					string jump = attributes.ContainsKey("jump") ? "#" + attributes["jump"] : "";
					string parStr = attributes.ContainsKey("par") ? attributes["par"] : null;
					#region Decode par array
					string[] par = null;
					if (parStr != null)
					{
						List<string> parList = new List<string>();
						foreach (string s in parStr.Split('&'))
						{
							if (s.Contains("="))
							{
								parList.Add(System.Web.HttpUtility.UrlDecode(s.Split('=')[0]));
								parList.Add(System.Web.HttpUtility.UrlDecode(s.Split('=')[1]));
							}
							else
							{
								parList.Add(System.Web.HttpUtility.UrlDecode(s));
								parList.Add("");
							}
						}
						par = parList.ToArray();
					}
					#endregion

					string styleContent = style.ContainsKey("content") ? style["content"] : "text";
					string styleDetails = style.ContainsKey("details") ? style["details"] : "none";
					bool styleDate = style.ContainsKey("date") ? bool.Parse(style["date"]) : false;
					int styleSnip = style.ContainsKey("snip") ? int.Parse(style["snip"]) : 0;
					bool styleRollover = style.ContainsKey("rollover") ? bool.Parse(style["rollover"]) : true;
					string stylePhoto = style.ContainsKey("photo") ? style["photo"] : "icon";
					bool styleLink = style.ContainsKey("link") ? bool.Parse(style["link"]) : true;

					string extraHtmlAttributes = "";
					string extraStyleAttribute = "";
					string extraStyleElements = "";
					string extraClassAttribute = "";
					string extraClassElements = "";
					foreach (string k in attributes.Keys)
					{
						if (k != "href" && k != "src" && k != "type" && k != "ref" && k != "style" && k != "app" && k != "date" && k != "par" && k != "class")
						{
							extraHtmlAttributes += " " + k + "=\"" + attributes[k] + "\"";
						}
					}

					foreach (string s in style.Keys)
					{
						if (s != "content" && s != "details" && s != "date" && s != "snip" && s != "rollover" && s != "photo" && s != "link")
						{
							extraStyleElements += s + ":" + style[s] + ";";
						}
					}
					if (extraStyleElements.Length > 0)
					{
						extraStyleAttribute = " style=\"" + extraStyleElements + "\"";
					}

					foreach (string s in classes)
					{
						extraClassElements += " " + s;
					}
					if (extraClassElements.Length > 0)
					{
						extraClassAttribute = " class=\"" + extraClassElements + "\"";
					}

					if (typeAtt == "usr")
					{
						#region Usr
						Usr u = new Usr(int.Parse(refAtt));
						string url = getObectPageUrl(u, app, date, par) + jump;

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						string rolloverHtml = styleRollover ? ((styleContent == "icon" || styleContent == "text-under-icon") ? u.RolloverNoPic : u.Rollover) : "";

						if (styleContent == "icon" || styleContent == "text-under-icon")
						{
							#region Pic
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(rolloverHtml);
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}
							sb.Append("<img src=\"");
							sb.Append(u.AnyPicPath);
							sb.Append("\"");
							if (styleContent == "icon" && !styleLink)
							{
								//Just image with no link around the image... lets apply any extra html to the image tag.
								if (!attributes.ContainsKey("width"))
									sb.Append(" width=\"100\"");

								if (!attributes.ContainsKey("height"))
									sb.Append(" height=\"100\"");

								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(" class=\"BorderBlack All" + extraClassElements + "\"");
								sb.Append(" />");
							}
							else
								sb.Append(" width=\"100\" height=\"100\" class=\"BorderBlack All\" />");
							if (styleLink)
								sb.Append("</a>");
							if (styleContent == "text-under-icon")
								sb.Append("<br />");
							#endregion
						}
						if (styleContent == "text" || styleContent == "text-under-icon")
						{
							#region Nickname
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(rolloverHtml);
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}
							sb.Append(getObjectName(u.NickNameDisplay, app, styleSnip));
							if (styleLink)
								sb.Append("</a>");
							#endregion
						}
						return sb.ToString();
						#endregion
					}
					else if (typeAtt == "event")
					{
						#region Event
						Event e = new Event(int.Parse(refAtt));
						string url = getObectPageUrl(e, app, date, par) + jump;

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						#region Container span
						if ((styleContent == "text" || styleContent == "text-under-icon") && !styleLink && (extraHtmlAttributes.Length > 0 || extraStyleAttribute.Length > 0 || extraClassAttribute.Length > 0) && (styleDate || styleDetails == "venue" || styleDetails == "place" || styleDetails == "country"))
						{
							sb.Append("<span");
							sb.Append(extraHtmlAttributes);
							sb.Append(extraStyleAttribute);
							sb.Append(extraClassAttribute);
							sb.Append(">");
						}
						#endregion

						if (styleContent == "icon" || styleContent == "text-under-icon")
						{
							#region Pic
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}
							sb.Append("<img src=\"");
							sb.Append(e.AnyPicPath);
							sb.Append("\"");
							if (styleContent == "icon" && !styleLink)
							{
								//Just image with no link around the image... lets apply any extra html to the image tag.
								if (!attributes.ContainsKey("width"))
									sb.Append(" width=\"100\"");

								if (!attributes.ContainsKey("height"))
									sb.Append(" height=\"100\"");

								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(" class=\"BorderBlack All" + extraClassElements + "\"");
								sb.Append(" />");
							}
							else
								sb.Append(" width=\"100\" height=\"100\" class=\"BorderBlack All\" />");

							if (styleLink)
								sb.Append("</a>");

							if (styleContent == "text-under-icon")
								sb.Append("<br />");

							#endregion
						}
						if (styleContent == "text" || styleContent == "text-under-icon")
						{
							#region Event link
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}

							sb.Append(getObjectName(e.Name, app, styleSnip));

							if (styleLink)
								sb.Append("</a>");
							#endregion

							#region Venue link
							if (styleDetails == "venue" || styleDetails == "place" || styleDetails == "country")
							{
								sb.Append(" @ ");
								if (styleLink)
								{
									sb.Append("<a href=\"");
									sb.Append(e.Venue.Url());
									sb.Append("\"");
									sb.Append(extraHtmlAttributes);
									sb.Append(extraStyleAttribute);
									sb.Append(extraClassAttribute);
									sb.Append(">");
								}
								sb.Append(Cambro.Misc.Utility.Snip(e.Venue.Name, styleSnip));
								if (styleLink)
									sb.Append("</a>");
							}
							#endregion

							#region Place link
							if (styleDetails == "place" || styleDetails == "country")
							{
								sb.Append(" in ");
								if (styleLink)
								{
									sb.Append("<a href=\"");
									sb.Append(e.Venue.Place.Url());
									sb.Append("\"");
									sb.Append(extraHtmlAttributes);
									sb.Append(extraStyleAttribute);
									sb.Append(extraClassAttribute);
									sb.Append(">");
								}
								if (styleDetails == "country")
								{
									sb.Append(Cambro.Misc.Utility.Snip(e.Venue.Place.Name, styleSnip));
								}
								else
								{
									sb.Append(Cambro.Misc.Utility.Snip(e.Venue.Place.NamePlain, styleSnip));
								}
								if (styleLink)
									sb.Append("</a>");

							}
							#endregion

							#region Date
							if (styleDate)
							{
								sb.Append(", ");
								sb.Append(e.FriendlyDate(false));
							}
							#endregion
						}

						#region End container span
						if ((styleContent == "text" || styleContent == "text-under-icon") && !styleLink && (extraHtmlAttributes.Length > 0 || extraStyleAttribute.Length > 0 || extraClassAttribute.Length > 0) && (styleDetails == "venue" || styleDetails == "place" || styleDetails == "country"))
						{
							sb.Append("</span>");
						}
						#endregion

						return sb.ToString();

						#endregion
					}
					else if (typeAtt == "venue")
					{
						#region Venue
						Venue v = new Venue(int.Parse(refAtt));
						string url = getObectPageUrl(v, app, date, par) + jump;

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						#region Container span
						if ((styleContent == "text" || styleContent == "text-under-icon") && !styleLink && (extraHtmlAttributes.Length > 0 || extraStyleAttribute.Length > 0 || extraClassAttribute.Length > 0) && (styleDetails == "place" || styleDetails == "country"))
						{
							sb.Append("<span");
							sb.Append(extraHtmlAttributes);
							sb.Append(extraStyleAttribute);
							sb.Append(extraClassAttribute);
							sb.Append(">");
						}
						#endregion

						if (styleContent == "icon" || styleContent == "text-under-icon")
						{
							#region Pic
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}
							sb.Append("<img src=\"");
							sb.Append(v.AnyPicPath);
							sb.Append("\"");
							if (styleContent == "icon" && !styleLink)
							{
								//Just image with no link around the image... lets apply any extra html to the image tag.
								if (!attributes.ContainsKey("width"))
									sb.Append(" width=\"100\"");

								if (!attributes.ContainsKey("height"))
									sb.Append(" height=\"100\"");

								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(" class=\"BorderBlack All" + extraClassElements + "\"");
								sb.Append(" />");
							}
							else
								sb.Append(" width=\"100\" height=\"100\" class=\"BorderBlack All\" />");
							if (styleLink)
								sb.Append("</a>");

							if (styleContent == "text-under-icon")
								sb.Append("<br />");
							#endregion
						}

						if (styleContent == "text" || styleContent == "text-under-icon")
						{
							#region Venue link
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}

							sb.Append(getObjectName(v.Name, app, styleSnip));

							if (styleLink)
								sb.Append("</a>");
							#endregion

							#region Place link
							if (styleDetails == "place" || styleDetails == "country")
							{
								sb.Append(" in ");
								if (styleLink)
								{
									sb.Append("<a href=\"");
									sb.Append(v.Place.Url());
									sb.Append("\"");
									sb.Append(extraHtmlAttributes);
									sb.Append(extraStyleAttribute);
									sb.Append(extraClassAttribute);
									sb.Append(">");
								}
								if (styleDetails == "country")
								{
									sb.Append(Cambro.Misc.Utility.Snip(v.Place.Name, styleSnip));
								}
								else
								{
									sb.Append(Cambro.Misc.Utility.Snip(v.Place.NamePlain, styleSnip));
								}
								if (styleLink)
									sb.Append("</a>");
							}
							#endregion
						}

						#region End container span
						if ((styleContent == "text" || styleContent == "text-under-icon") && !styleLink && (extraHtmlAttributes.Length > 0 || extraStyleAttribute.Length > 0 || extraClassAttribute.Length > 0) && (styleDetails == "place" || styleDetails == "country"))
						{
							sb.Append("</span>");
						}
						#endregion

						return sb.ToString();

						#endregion
					}
					else if (typeAtt == "place")
					{
						#region Place
						Place p = new Place(int.Parse(refAtt));
						string url = getObectPageUrl(p, app, date, par) + jump;

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						#region Container span
						if ((styleContent == "text" || styleContent == "text-under-icon") && !styleLink && (extraHtmlAttributes.Length > 0 || extraStyleAttribute.Length > 0 || extraClassAttribute.Length > 0))
						{
							sb.Append("<span");
							sb.Append(extraHtmlAttributes);
							sb.Append(extraStyleAttribute);
							sb.Append(extraClassAttribute);
							sb.Append(">");
						}
						#endregion

						if (styleContent == "icon" || styleContent == "text-under-icon")
						{
							#region Pic
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}
							sb.Append("<img src=\"");
							sb.Append(p.AnyPicPath);
							sb.Append("\"");
							if (styleContent == "icon" && !styleLink)
							{
								//Just image with no link around the image... lets apply any extra html to the image tag.
								if (!attributes.ContainsKey("width"))
									sb.Append(" width=\"100\"");

								if (!attributes.ContainsKey("height"))
									sb.Append(" height=\"100\"");

								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								if (style.ContainsKey("border"))
								{
									sb.Append(extraClassAttribute);
								}
								else
								{
									sb.Append(" class=\"BorderBlack All" + extraClassElements + "\"");
								}
								
								sb.Append(" />");
							}
							else
								sb.Append(" width=\"100\" height=\"100\" class=\"BorderBlack All\" />");
							if (styleLink)
								sb.Append("</a>");
							if (styleContent == "text-under-icon")
								sb.Append("<br />");
							#endregion
						}

						if (styleContent == "text" || styleContent == "text-under-icon")
						{
							#region Place link
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}
							if (styleDetails == "country")
							{
								sb.Append(getObjectName(p.Name, app, styleSnip));
							}
							else
							{
								sb.Append(getObjectName(p.NamePlain, app, styleSnip));
							}
							if (styleLink)
								sb.Append("</a>");
							#endregion
						}

						#region End container span
						if ((styleContent == "text" || styleContent == "text-under-icon") && !styleLink && (extraHtmlAttributes.Length > 0 || extraStyleAttribute.Length > 0 || extraClassAttribute.Length > 0))
						{
							sb.Append("</span>");
						}
						#endregion

						return sb.ToString();

						#endregion
					}
					else if (typeAtt == "group")
					{
						#region Group
						Group g = new Group(int.Parse(refAtt));
						string url = getObectPageUrl(g, app, date, par) + jump;

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						#region Group link
						if (styleLink)
						{
							sb.Append("<a href=\"");
							sb.Append(url);
							sb.Append("\"");
							sb.Append(extraHtmlAttributes);
							sb.Append(extraStyleAttribute);
							sb.Append(extraClassAttribute);
							sb.Append(">");
						}
						sb.Append(getObjectName(g.FriendlyName, app, styleSnip));
						if (styleLink)
							sb.Append("</a>");
						#endregion

						return sb.ToString();

						#endregion
					}
					else if (typeAtt == "brand")
					{
						#region Brand
						Brand b = new Brand(int.Parse(refAtt));
						string url = getObectPageUrl(b, app, date, par) + jump;

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						#region Brand link
						if (styleLink)
						{
							sb.Append("<a href=\"");
							sb.Append(url);
							sb.Append("\"");
							sb.Append(extraHtmlAttributes);
							sb.Append(extraStyleAttribute);
							sb.Append(extraClassAttribute);
							sb.Append(">");
						}
						sb.Append(getObjectName(b.FriendlyName, app, styleSnip));
						if (styleLink)
							sb.Append("</a>");
						#endregion

						return sb.ToString();

						#endregion
					}
					else if (typeAtt == "photo")
					{
						#region Photo
						Photo p = new Photo(int.Parse(refAtt));
						string url = getObectPageUrl(p, app, date, par) + jump;

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						#region Link
						if (styleLink)
						{
							sb.Append("<a href=\"");
							sb.Append(url);
							sb.Append("\"");
							sb.Append(extraHtmlAttributes);
							sb.Append(extraStyleAttribute);
							sb.Append(extraClassAttribute);
							sb.Append(">");
						}
						#endregion

						if (app != null && app == "chat")
						{
							#region For chat app, just show the name of the parent...
							sb.Append(Cambro.Misc.Utility.Snip(((IName)p.ParentObject).Name, styleSnip) + " (chat)");
							#endregion
						}
						else
						{
							#region Image tag
							sb.Append("<img");

							#region Src attribute
							sb.Append(" src=\"");
							if (stylePhoto == "thumb")
								sb.Append(p.ThumbPath);
							else if (stylePhoto == "icon")
								sb.Append(p.IconPath);
							else if (stylePhoto == "web")
								sb.Append(p.WebPath);
							sb.Append("\"");
							#endregion

							#region Width attribute
							if (styleLink || !attributes.ContainsKey("width"))
							{
								sb.Append(" width=\"");
								if (stylePhoto == "thumb")
									sb.Append(p.ThumbWidth);
								else if (stylePhoto == "icon")
									sb.Append("100");
								else if (stylePhoto == "web")
									sb.Append(p.WebWidth);
								sb.Append("\"");
							}
							#endregion

							#region Height attribute
							if (styleLink || !attributes.ContainsKey("height"))
							{
								sb.Append(" height=\"");
								if (stylePhoto == "thumb")
									sb.Append(p.ThumbHeight);
								else if (stylePhoto == "icon")
									sb.Append("100");
								else if (stylePhoto == "web")
									sb.Append(p.WebHeight);
								sb.Append("\"");
							}
							#endregion

							#region Extra html attributes
							if (!styleLink)
							{
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
							}
							#endregion

							#region Style attribute
							if (styleLink)
							{
								
								sb.Append(" class=\"BorderBlack All\"");
							}
							else if (style.ContainsKey("border"))
							{
								sb.Append(extraClassAttribute);
							}
							else
							{
								sb.Append(" class=\"BorderBlack All" + extraClassElements + "\"");
							}
							#endregion

							#region Rollover
							if (styleRollover && stylePhoto != "web")
							{
								sb.Append(" onmouseover=\"stm('<img src=" + p.WebPath + " width=" + p.WebWidth + " height=" + p.WebHeight + " class=Block />');\" onmouseout=\"htm();\"");
							}
							#endregion

							sb.Append(" />");
							#endregion
						}

						#region End link
						if (styleLink)
							sb.Append("</a>");
						#endregion

						return sb.ToString();

						#endregion
					}
					else if (typeAtt == "misc")
					{
						#region Misc
						Misc mi = new Misc(int.Parse(refAtt));

						if (tagName == "dsi:link")
							return "<a href=\"" + mi.Url() + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						if (mi.Extention.ToLower() == "jpg" || mi.Extention.ToLower() == "jpeg" || mi.Extention.ToLower() == "gif" || mi.Extention.ToLower() == "png")
						{
							StringBuilder sb = new StringBuilder();

							#region Width and height
							int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : mi.Width;
							int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : mi.Height;
							#endregion

							#region Image tag
							sb.Append("<img src=\"");
							sb.Append(mi.Url());
							sb.Append("\" width=\"");
							sb.Append(width);
							sb.Append("\" height=\"");
							sb.Append(height);
							sb.Append("\" border=\"0\"");
							sb.Append(extraHtmlAttributes);
							sb.Append(extraStyleAttribute);
							sb.Append(extraClassAttribute);
							sb.Append(" />");
							#endregion

							return sb.ToString();

						}
						else if (mi.Extention.ToLower() == "swf")
						{
							#region Swf
							return getFlashAttributesFromSgml(uniqueId, mi.Url(), attributes);
							#endregion
						}
						#endregion
					}
					else if (typeAtt == "article")
					{
						#region Article
						Article a = new Article(int.Parse(refAtt));
						string url = getObectPageUrl(a, app, date, par) + jump;

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						#region Article link
						if (styleLink)
						{
							sb.Append("<a href=\"");
							sb.Append(url);
							sb.Append("\"");
							sb.Append(extraHtmlAttributes);
							sb.Append(extraStyleAttribute);
							sb.Append(extraClassAttribute);
							sb.Append(">");
						}
						sb.Append(getObjectName(a.FriendlyName, app, styleSnip));
						if (styleLink)
							sb.Append("</a>");
						#endregion

						return sb.ToString();

						#endregion
					}
					else if (typeAtt == "url") //if (attributes.ContainsKey("href"))
					{
						#region Url
						string url = attributes.ContainsKey("href") ? attributes["href"] : "";
						#region Get name
						string name = url;
						string path = url;
						string domain = url;
						string targetAttribute = "";
						try
						{
							if (UrlRegex.IsMatch(url))
							{
								Match urlMatch = UrlRegex.Match(url);
								if (urlMatch.Groups[3].Value.StartsWith("www."))
									name = urlMatch.Groups[3].Value.Substring(4);
								else
									name = urlMatch.Groups[3].Value;

								domain = urlMatch.Groups[3].Value;
								path = urlMatch.Groups[4].Value;
								if (!domain.ToLower().EndsWith(".dontstayin.com") && !attributes.ContainsKey("target"))
									targetAttribute = " target=\"_blank\"";

							}
						}
						catch
						{ }
						#endregion

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + targetAttribute + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						if (path.ToLower().EndsWith(".jpg") || path.ToLower().EndsWith(".jpeg") || path.ToLower().EndsWith(".gif") || path.ToLower().EndsWith(".png"))
						{
							#region Image tag
							sb.Append("<img");

							#region Src attribute
							sb.Append(" src=\"");
							sb.Append(url);
							sb.Append("\"");
							#endregion

							sb.Append(extraHtmlAttributes);

							#region Style attribute
							if (domain.EndsWith(".dontstayin.com") && !style.ContainsKey("border"))
							{
								sb.Append(" class=\"BorderBlack All" + extraClassElements + "\"");
							}
							else
							{
								sb.Append(extraClassAttribute);
							}
							#endregion

							sb.Append(extraStyleAttribute);

							sb.Append(" />");
							#endregion
						}
						else if (path.ToLower().EndsWith(".mp3") || path.ToLower().EndsWith(".wav"))
						{
							#region Audio
							int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 290;
							int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 24;
							string audioPlayerSwfPath = Storage.Path(new Guid("7abb3119-f8ad-43ff-be01-764b2ae111fc"), "swf", Storage.Stores.Pix);
							return GetFlash(uniqueId, height, width, false, "load", audioPlayerSwfPath, "soundFile", url, "autoStart", "no") +
								@"<a href=""" + url + @"""><img src=""/gfx/download-button2.png"" width=""73"" height=""16"" border=""0"" /></a>";
							#endregion
						}
						else if (path.ToLower().EndsWith(".swf"))
						{
							#region Swf
							return getFlashAttributesFromSgml(uniqueId, path, attributes);
							#endregion
						}
						else if (path.ToLower().EndsWith(".flv"))
						{
							#region Flv
							int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 450;
							int height = attributes.ContainsKey("height") ? (int.Parse(attributes["height"]) + 20) : 357;
							bool nsfw = attributes.ContainsKey("nsfw") ? bool.Parse(attributes["nsfw"].ToLower()) : false;
							string draw = attributes.ContainsKey("draw") ? attributes["draw"].ToLower() : "auto";
							return GetFlash(uniqueId, height, width, nsfw, draw, "/misc/flvplayer.swf", "file", url, "autoStart", "0");
							#endregion
						}
						else
						{
							#region Link
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(targetAttribute);
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}
							#endregion
							#region Name
							sb.Append(name);
							#endregion
							#region End link
							if (styleLink)
								sb.Append("</a>");
							#endregion
						}

						return sb.ToString();

						#endregion
					}
					else if (typeAtt == "room")
					{
						#region Chat room
						Guid guid = refAtt.UnPackGuid();
						Chat.RoomSpec room = Chat.RoomSpec.FromGuid(guid);

						if (room == null)
							return "[Room not found]";
						
						StringBuilder sb = new StringBuilder();
						
						if (tagName == "dsi:link")
							room.LinkHtmlAppendJustStartOfAnchorTag(sb, "selected-onyellow", extraHtmlAttributes, extraStyleAttribute, extraClassAttribute);
						else
							room.LinkHtmlAppend(sb, "selected-onyellow", extraHtmlAttributes, extraStyleAttribute, extraClassAttribute);

						return sb.ToString();

						#endregion
					}
					#endregion
				}
				return "[Invalid tag " + tagName + "]";
			}
			catch (Exception ex)
			{
				if (Vars.DevEnv)
					throw ex;

				return "[Error in " + tagName + " tag]";
			}
		}
コード例 #14
0
ファイル: ResourceParser.cs プロジェクト: ragingsmurf/myLegis
        /// <summary>
        /// Detects URLs in styles.
        /// </summary>
        /// <param name="baseUri">The base URI.</param>
        /// <param name="attributeName">Name of the attribute.</param>
        /// <param name="attributeValue">The attribute value.</param>
        /// <returns></returns>
        //private List<UriResourceInformation> ExtractStyleUrls(
        //    Uri baseUri,
        //    string attributeName,
        //    string attributeValue)
        //{
        //    List<UriResourceInformation> result =
        //        new List<UriResourceInformation>();
        //    if (string.Compare(attributeName, @"style", true) == 0)
        //    {
        //        if (attributeValue != null &&
        //            attributeValue.Trim().Length > 0)
        //        {
        //            MatchCollection matchs = Regex.Matches(
        //                attributeValue,
        //                @"url\s*\(\s*([^\)\s]+)\s*\)",
        //                RegexOptions.Singleline | RegexOptions.IgnoreCase);
        //            if (matchs.Count > 0)
        //            {
        //                foreach (Match match in matchs)
        //                {
        //                    if (match != null && match.Success)
        //                    {
        //                        string url = match.Groups[1].Value;
        //                        UriResourceInformation ui =
        //                            new UriResourceInformation(
        //                            _settings.Options,
        //                            url,
        //                            new Uri(url, UriKind.RelativeOrAbsolute),
        //                            baseUri,
        //                            UriType.Resource,
        //                            _uriInfo.AbsoluteUri,
        //                            );
        //                        bool isOnSameSite =
        //                            ui.IsOnSameSite(baseUri);
        //                        if ((isOnSameSite ||
        //                            !_settings.Options.StayOnSite) &&
        //                            ui.IsProcessableUri)
        //                        {
        //                            result.Add(ui);
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //    }
        //    return result;
        //}
        /// <summary>
        /// Gets the doc reader.
        /// </summary>
        /// <param name="html">The HTML.</param>
        /// <param name="baseUri">The base URI.</param>
        /// <returns></returns>
        private static XmlReader GetDocReader(
            string html,
            Uri baseUri)
        {
            SgmlReader r = new SgmlReader();

            if (baseUri != null &&
                !string.IsNullOrEmpty(baseUri.ToString()))
                r.SetBaseUri(baseUri.ToString());
            r.DocType = @"HTML";
            r.WhitespaceHandling = WhitespaceHandling.All;
            r.CaseFolding = CaseFolding.None;
            StringReader sr = new StringReader(html);
            r.InputStream = sr;
            r.Read();

            return r;
        }
コード例 #15
0
ファイル: Test.cs プロジェクト: panuganti/nreadability
        void Process(SgmlReader reader, string uri, bool loadAsStream)
        {
            if (uri == null) {
                reader.InputStream = Console.In;
            }
            else if (loadAsStream) {
                Uri location = new Uri(uri);
                if (location.IsFile) {
                    reader.InputStream = new StreamReader(uri);
                } else {
                    WebRequest wr = WebRequest.Create(location);
                    reader.InputStream = new StreamReader(wr.GetResponse().GetResponseStream());
                }
            } else {
                reader.Href = uri;
            }

            if (debug) {
                Debug(reader);
                reader.Close();
                return;
            }
            if (crawl) {
                StartCrawl(reader, uri, basify);
                return;
            }

            if (this.encoding == null) {
                this.encoding = reader.GetEncoding();
            }

            XmlTextWriter w = null;
            if (output != null) {
                w = new XmlTextWriter(output, this.encoding);
            }
            else {
                w = new XmlTextWriter(Console.Out);
            }
            if (formatted) w.Formatting = Formatting.Indented;
            if (!noxmldecl) {
                w.WriteStartDocument();
            }
            if (testdoc) {
                XmlDocument doc = new XmlDocument();
                try {
                    doc.Load(reader);
                    doc.WriteTo(w);
                } catch (XmlException e) {
                    Console.WriteLine("Error:" + e.Message);
                    Console.WriteLine("at line " + e.LineNumber + " column " + e.LinePosition);
                }
            } else {
                reader.Read();
                while (!reader.EOF) {
                    w.WriteNode(reader, true);
                }
            }
            w.Flush();
            w.Close();
        }
コード例 #16
0
ファイル: Test.cs プロジェクト: panuganti/nreadability
 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());
         }
     }
 }
コード例 #17
0
        /// <summary>
        /// 读取html页面内容
        /// </summary>
        /// <param name="uri">网址</param>
        /// <param name="xpath">xpath标签</param>
        /// <returns></returns>
        private string GetWellFormedHTML(string uri, string xpath)
        {
            StreamReader sReader = null;//读取字节流
            StringWriter sw = null;//写入字符串
            SgmlReader reader = null;//sgml读取方法
            XmlTextWriter writer = null;//生成xml数据流
            try
            {
                if (uri == String.Empty)
                    uri = "http://www.ypshop.net/list--91-940-940--search-1.html";
                WebClient webclient = new WebClient();
                webclient.Encoding = Encoding.UTF8;
                //页面内容
                string strWebContent = webclient.DownloadString(uri);

                reader = new SgmlReader();
                reader.DocType = "HTML";
                reader.InputStream = new StringReader(strWebContent);

                sw = new StringWriter();
                writer = new XmlTextWriter(sw);
                writer.Formatting = Formatting.Indented;
                while (reader.Read())
                {
                    if (reader.NodeType != XmlNodeType.Whitespace)
                    {
                        writer.WriteNode(reader, true);
                    }
                }
                //return sw.ToString();
                if (xpath == null)
                {
                    return sw.ToString();
                }
                else
                { //Filter out nodes from HTML
                    StringBuilder sb = new StringBuilder();
                    XPathDocument doc = new XPathDocument(new StringReader(sw.ToString()));
                    XPathNavigator nav = doc.CreateNavigator();
                    XPathNodeIterator nodes = nav.Select(xpath);
                    while (nodes.MoveNext())
                    {
                        sb.Append(nodes.Current.Value + " ");
                    }
                    return sb.ToString();
                }
            }
            catch (Exception exp)
            {
                writer.Close();
                reader.Close();
                sw.Close();
                sReader.Close();
                return exp.Message;
            }
        }
コード例 #18
0
ファイル: AlbumService.cs プロジェクト: arbium/democratia2
        public static AlbumItem AddVideo(UserContainer currContext, Guid albumId, string title, string description, string url, string embedCode)
        {
            var album = DataService.PerThread.AlbumSet.SingleOrDefault(x => x.Id == albumId);
            if (album == null)
                throw new BusinessLogicException("Указан неверный идентификатор");

            if (string.IsNullOrWhiteSpace(title))
                throw new BusinessLogicException("Не указано название видео");

            if (currContext != null)
            {
                if (album.GroupId.HasValue)
                {
                    var gm = GroupService.UserInGroup(currContext.Id, album.GroupId.Value);
                    if (gm == null)
                        throw new BusinessLogicException("Вы не состоите в группе");

                    if (album.IsOpen)
                    {
                        if (!(gm.State == (byte)GroupMemberState.Approved || gm.State == (byte)GroupMemberState.Moderator))
                            throw new BusinessLogicException("Только члены группы могут добавлять видео в альбом");
                    }
                    else if (gm.State != (byte)GroupMemberState.Moderator)
                        throw new BusinessLogicException("Только модераторы могут добавлять видео в альбом");
                }
                else if (album.UserId.HasValue)
                {
                    if (album.UserId != currContext.Id)
                        throw new BusinessLogicException("Нельзя добавлять видео в чужой альбом");
                }
                else
                    throw new BusinessLogicException("Альбом ни к чему не привязан");
            }

            string src;

            if (!string.IsNullOrWhiteSpace(embedCode))
            {
                using (var sgml = new SgmlReader())
                {
                    sgml.InputStream = new StringReader(embedCode);
                    sgml.Read();
                    src = sgml.GetAttribute("src");
                }
            }
            else if (!string.IsNullOrWhiteSpace(url))
            {
                var uri = new Uri(url);
                src = url; // TODO: мб лучше regexp для вычленения src

                switch (uri.Host.Replace("www.", string.Empty))
                {
                    case "youtube.com":
                        //src = uri.Scheme + "://" + uri.Host + "/embed/" + HttpUtility.ParseQueryString(uri.Query).GetValues("v").First(); // это для iframe
                        src = uri.Scheme + "://" + uri.Host + "/v/" + HttpUtility.ParseQueryString(uri.Query).GetValues("v").First();
                        break;

                    case "youtu.be":
                        //src = uri.Scheme + "://youtube.com/embed/" + uri.Segments[1]; // это для iframe
                        src = uri.Scheme + "://youtube.com/v/" + uri.Segments[1];
                        break;

                    /*case "vimeo.com":
                        src = uri.Scheme + "://" + "player." + uri.Host + "/video" + uri.PathAndQuery;
                        break;

                    case "dailymotion.com":
                        var query = uri.Fragment.Replace("#", string.Empty);
                        src = uri.Scheme + "://" + uri.Host + "/embed/video/" + HttpUtility.ParseQueryString(query).GetValues("videoId").First();
                        break;*/

                    case "e2-e4.tv":
                        src = uri.Scheme + "://" + uri.Host + uri.PathAndQuery + "/swf/player2.swf";
                        break;

                    case "e2e4.tv":
                        src = uri.Scheme + "://" + uri.Host + uri.PathAndQuery + "/swf/player2.swf";
                        break;
                }
            }
            else
                throw new BusinessLogicException("Источник видео не указан");

            var albumItem = new AlbumItem
            {
                AlbumId = albumId,
                Title = title,
                Description = description,
                Type = (byte)AlbumItemType.Video,
                Src = src,
                CreationDate = DateTime.Now
            };

            DataService.PerThread.AlbumItemSet.AddObject(albumItem);
            DataService.PerThread.LoadProperty(albumItem, x => x.Album);

            albumItem.Album.ChangeDate = DateTime.Now;

            DataService.PerThread.SaveChanges();

            return albumItem;
        }
コード例 #19
0
        /// <summary>
        private string GetWellFormedHTML_Handle(string uri)
        {
            StreamReader sReader = null;
            StringWriter sw = null;
            SgmlReader reader = null;
            XmlTextWriter writer = null;
            try
            {
                if (uri == String.Empty) uri = "http://www.ypshop.net/list--91-940-940--search-1.html";
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
                HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                sReader = new StreamReader(res.GetResponseStream());

                reader = new SgmlReader();
                reader.DocType = "HTML";
                reader.InputStream = new StringReader(sReader.ReadToEnd());

                sw = new StringWriter();
                writer = new XmlTextWriter(sw);
                writer.Formatting = Formatting.Indented;
                while (reader.Read())
                {
                    if (reader.NodeType != XmlNodeType.Whitespace)
                    {
                        writer.WriteNode(reader, true);
                    }
                }

                StringBuilder sb = new StringBuilder();
                XPathDocument doc = new XPathDocument(new StringReader(sw.ToString()));
                XPathNavigator nav = doc.CreateNavigator();
                //XPathNodeIterator nodes = nav.Select(xpath);
                //while (nodes.MoveNext())
                //{
                //    sb.Append(nodes.Current.Value + " ");
                //}
                return sb.ToString();

            }
            catch (Exception exp)
            {
                writer.Close();
                reader.Close();
                sw.Close();
                sReader.Close();
                return exp.Message;
            }
        }
コード例 #20
0
ファイル: Tests.cs プロジェクト: VitaliyBoris/SGMLReader
        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());
            }
        }
コード例 #21
0
        /// <summary>
        /// Parse a HTML to XML and returns a string, if error occurs returns an exception.
        /// </summary>
        /// <remarks> Use this method when you want to catch a parsing error.</remarks>
        /// <param name="html"> HTML string to parse.</param>
        /// <returns>A string with the parsed value.</returns>	
        public string GetParsableString(string html)
        {
            html = PreProcessHtml(html);
            SgmlReader reader = new SgmlReader();

            // set SgmlReader values
            reader.DocType = "HTML";

            // lower case all
            reader.InputStream = new StringReader(html);

            // write to xml
            StringWriter sw = new StringWriter();
            XmlTextWriter w = new XmlTextWriter(sw);

            w.Formatting = Formatting.Indented;

            try
            {
                while (reader.Read())
                {
                    if ( (reader.NodeType != XmlNodeType.DocumentType) && (this.ParserProperties.RemoveDocumentType) )
                    {
                        if ( reader.NodeType != XmlNodeType.Whitespace )
                        {
                            // Write entire reader to xml
                            w.WriteNode(reader, true);
                        }
                    }
                }

                return PostProcessHtml(sw.ToString());
            }
            catch
            {
                throw;
            }
            finally
            {

                reader.Close();
                w.Close();
            }
        }