This commit is contained in:
headhunter45_cp
2010-09-26 06:31:06 +00:00
parent dfa1aeb1b9
commit d280868fc8
31 changed files with 1945 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<ProjectGuid>730f03d9-cb96-43a9-88e3-a8687a66cf5e</ProjectGuid>
<ProjectTypeGuids>{96E2B04D-8817-42c6-938A-82C39BA4D311};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<XnaFrameworkVersion>v3.1</XnaFrameworkVersion>
<PlatformTarget>x86</PlatformTarget>
<OutputPath>bin\$(Platform)\$(Configuration)</OutputPath>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<XnaPlatform>Windows</XnaPlatform>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<XnaPlatform>Windows</XnaPlatform>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.EffectImporter, Version=3.1.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.FBXImporter, Version=3.1.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.TextureImporter, Version=3.1.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.XImporter, Version=3.1.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.AudioImporters, Version=3.1.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.VideoImporters, Version=3.1.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,10 @@
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Nodes
{
public class HtmlBrNode: HtmlNode
{
public override string ToString()
{
return Environment.NewLine;
}
public HtmlBrNode()
{
Type = HtmlNodeType.Br;
}
public override string TagName
{
get { return StaticTagName; }
}
public static string StaticTagName
{
get { return "br"; }
}
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Nodes
{
public class HtmlDivNode: HtmlNode
{
public static string StaticTagName { get { return "div"; } }
public override string TagName { get { return StaticTagName; } }
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Nodes
{
public class HtmlDocumentNode: HtmlNode
{
public HtmlDocumentNode()
{
Type = HtmlNodeType.Document_;
}
public override string InnerHtml
{
get
{
StringBuilder sb = new StringBuilder();
foreach (HtmlNode child in Children)
{
sb.Append(child.OuterHtml);
}
return sb.ToString();
}
}
public override string OuterHtml
{
get
{
return InnerHtml;
}
}
public override string TagName
{
get { return "_Document"; }
}
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Nodes
{
public class HtmlImgNode: HtmlNode
{
public static string StaticTagName { get { return "img"; } }
public override string TagName { get { return StaticTagName; } }
}
}

View File

@@ -0,0 +1,191 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Nodes
{
public abstract class HtmlNode
{
public List<HtmlNode> Children { get; set; }
public HtmlNodeType Type { get; protected set; }
public List<KeyValuePair<string, string>> Attributes { get; set; }
public List<KeyValuePair<string, string>> Styles { get; set; }
public HtmlNode()
{
Attributes = new List<KeyValuePair<string, string>>();
Children = new List<HtmlNode>();
Styles = new List<KeyValuePair<string, string>>();
}
public virtual String InnerHtml
{
get
{
StringBuilder sb = new StringBuilder();
foreach (HtmlNode childNode in Children)
{
sb.Append(childNode.OuterHtml);
}
return sb.ToString();
}
}
public virtual String OuterHtml
{
get
{
string styles = GetStylesString();
string attributes = GetAttributesString();
StringBuilder sb = new StringBuilder();
sb.Append("<");
sb.Append(TagName);
if (!String.IsNullOrEmpty(styles))
{
sb.Append(" ");
sb.Append(styles);
}
if (!String.IsNullOrEmpty(attributes))
{
sb.Append(" ");
sb.Append(attributes);
}
if (Children.Count > 0)
{
sb.Append(">");
sb.Append(InnerHtml);
sb.Append("</");
sb.Append(TagName);
sb.Append(">");
}
else
{
sb.Append(" />");
}
return sb.ToString();
}
}
public abstract String TagName{get;}
protected virtual String GetAttributesString()
{
int numAttributes = Attributes.Count;
if (numAttributes == 0)
{
return String.Empty;
}
else if (numAttributes == 1)
{
return Attributes[0].Key + "=\"" + Attributes[0].Value + "\"";
}
else
{
StringBuilder sb = new StringBuilder();
sb.Append(Attributes[0].Key + "=\"" + Attributes[0].Value + "\"");
foreach (KeyValuePair<string, string> attribute in Attributes.Skip(1))
{
sb.Append(" " + attribute.Key + "=\"" + attribute.Value + "\"");
}
return sb.ToString();
}
}
protected virtual String GetStylesString()
{
int numStyles = Styles.Count;
if (numStyles == 0)
{
return String.Empty;
}
else if (numStyles == 1)
{
return "style=\"" + Styles[0].Key + ":" + Styles[0].Value + ";\"";
}
else
{
StringBuilder sb = new StringBuilder();
sb.Append("style=\"" + Styles[0].Key + ":" + Styles[0].Value + ";\"");
foreach (KeyValuePair<string, string> style in Styles.Skip(1))
{
sb.Append(";" + style.Key + ":" + style.Value);
}
sb.Append("\"");
return sb.ToString();
}
}
public void AddAttribute(KeyValuePair<string, string> attribute)
{
KeyValuePair<string, string> newAttribute = new KeyValuePair<string, string>(attribute.Key.ToLower(), attribute.Value);
if (newAttribute.Key == "style")
{
ClearStyles();
String styleString = newAttribute.Value;
string[] stylePairStrings = styleString.Split(new char[] { ';' });
KeyValuePair<string, string> style;
foreach (string stylePairString in stylePairStrings)
{
string[] temp = stylePairString.Split(new char[] { ':' });
if (temp.Length == 1)
{
style = new KeyValuePair<string, string>(temp[0], String.Empty);
}
else if (temp.Length >= 2)
{
style = new KeyValuePair<string, string>(temp[0], temp[1]);
}
else
{
style = new KeyValuePair<string, string>();
}
if (!String.IsNullOrEmpty(style.Key))
{
AddStyle(style);
}
}
}
else
{
Attributes.RemoveAll(i => i.Key == newAttribute.Key);
Attributes.Add(newAttribute);
}
}
private void ClearStyles()
{
Styles.Clear();
}
public void AddStyle(KeyValuePair<string, string> style)
{
KeyValuePair<string, string> newStyle = new KeyValuePair<string,string>(style.Key.ToLower(), style.Value);
Styles.RemoveAll(i => i.Key == newStyle.Key);
Styles.Add(newStyle);
}
}
public enum HtmlNodeType { Document_, Text_, Br, Span, Img, Paragraph, Div }
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Nodes
{
public class HtmlSpanNode: HtmlNode
{
public HtmlSpanNode()
{
Type = HtmlNodeType.Span;
}
public HtmlSpanNode(String text)
:this()
{
Children.Add(new HtmlTextNode(text));
}
public HtmlSpanNode(IEnumerable<HtmlNode> children)
:this()
{
foreach (HtmlNode child in children)
{
Children.Add(child);
}
}
public override string TagName
{
get { return StaticTagName; }
}
public static string StaticTagName { get { return "span"; } }
}
}

View File

@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace PlanB.Html.Nodes
{
public class HtmlTextNode: HtmlNode
{
public String Text { get; set; }
public override string ToString()
{
return Text;
}
public HtmlTextNode()
{
Text = String.Empty;
Type = HtmlNodeType.Text_;
}
public HtmlTextNode(String text)
{
Text = text;
Type = HtmlNodeType.Text_;
}
public override string InnerHtml
{
get
{
return String.Empty;
}
}
public override string OuterHtml
{
get
{
return Entitize(Text);
}
}
public override string TagName
{
get { return "_Text"; }
}
private string Entitize(string Text)
{
string temp = Text;
temp = temp.Replace("&", "&amp;");
temp = temp.Replace("<", "&lt;");
temp = temp.Replace(">", "&gt;");
temp = temp.Replace("\"", "&quot;");
return temp;
}
}
}

View File

@@ -0,0 +1,289 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using PlanB.Html.Nodes;
using System.Text;
using PlanB.Html.Tokens;
using System.Text.RegularExpressions;
namespace PlanB.Html
{
public class Parser
{
public static List<HtmlToken> Tokenize(string htmlText)
{
List<HtmlToken> tokens = new List<HtmlToken>();
int position = 0;
int startOfNextToken = htmlText.IndexOf("<");
//If the whole document is text then just create one HtmlTextToken
if (startOfNextToken == -1)
{
tokens.Add(new HtmlTextToken(htmlText));
return tokens;
}
while (startOfNextToken >= 0)
{
if (startOfNextToken > position)
{
tokens.Add(new HtmlTextToken(htmlText.Substring(position, startOfNextToken - position)));
}
//Identify the type of token we are aproaching
string tokenText = htmlText.Substring(startOfNextToken);
string tokenName = String.Empty;
Regex r = new Regex(@"<(?<tagName>/?\w+)((\s+)(?<attributeName>\w*)=\""(?<attributeValue>[^""]*)\"")*(\s*)(/)?(\s*)>");
r = new Regex(@"<(?<tagName>/?\w+)(((\s+((?<attributeName>\w+)=(""(?<attributeValue>[^""]*)""))\s*))|((\s+((?<attributeName>\w+)=('(?<attributeValue>[^']*)'))\s*))|((\s+((?<attributeName>\w+)=(?<attributeValue>[^\s>]*))\s*)))*\s*(/)?(\s*)>");
Match m = r.Match(tokenText);
Console.WriteLine(m.ToString());
tokenName = m.Groups["tagName"].Value;
if (tokenName == HtmlSpanNode.StaticTagName)//"span"
{
//TODO: Handle attributes
HtmlBeginSpanToken token = new HtmlBeginSpanToken();
token.AddAttributes(m);
tokens.Add(token);
position = htmlText.IndexOf(">", startOfNextToken) + 1;
startOfNextToken = htmlText.IndexOf("<", position);
}
else if (tokenName == "/" + HtmlSpanNode.StaticTagName)//"/span"
{
tokens.Add(new HtmlEndSpanToken());
position = htmlText.IndexOf(">", startOfNextToken) + 1;
startOfNextToken = htmlText.IndexOf("<", position);
}
else if (tokenName == HtmlBrNode.StaticTagName)//"br"
{
HtmlBrToken token = new HtmlBrToken();
token.AddAttributes(m);
tokens.Add(token);
position = htmlText.IndexOf(">", startOfNextToken) + 1;
startOfNextToken = htmlText.IndexOf("<", position);
}
else if(tokenName == HtmlDivNode.StaticTagName)//"div"
{
HtmlBeginDivToken token = new HtmlBeginDivToken();
token.AddAttributes(m);
tokens.Add(token);
position = htmlText.IndexOf(">", startOfNextToken) + 1;
startOfNextToken = htmlText.IndexOf("<", position);
}
else if (tokenName == "/" + HtmlDivNode.StaticTagName)//"/div"
{
tokens.Add(new HtmlEndDivToken());
position = htmlText.IndexOf(">", startOfNextToken) + 1;
startOfNextToken = htmlText.IndexOf("<", position);
}
else if (tokenName == HtmlImgNode.StaticTagName)//"img"
{
HtmlImgToken token = new HtmlImgToken();
token.AddAttributes(m);
tokens.Add(token);
position = htmlText.IndexOf(">", startOfNextToken) + 1;
startOfNextToken = htmlText.IndexOf("<", position);
}
else
{
position = startOfNextToken;
startOfNextToken = htmlText.IndexOf("<", startOfNextToken + 1);
}
}
if (htmlText.Length - 1 > position)
{
tokens.Add(new HtmlTextToken(htmlText.Substring(position)));
}
return tokens;
}
public static HtmlNode Parse(List<HtmlToken> tokens)
{
HtmlNode rootNode = new HtmlDocumentNode();
int position = 0;
GetContents(rootNode, tokens, ref position);
return rootNode;
}
private static void GetContents(HtmlNode parentNode, List<HtmlToken> tokens, ref int position)
{
HtmlToken currentToken;
bool throwExceptions = false;
HtmlTextToken textToken = null;
HtmlBrToken brToken = null;
HtmlBeginSpanToken beginSpanToken = null;
HtmlEndSpanToken endSpanToken = null;
HtmlBeginDivToken beginDivToken = null;
HtmlEndDivToken endDivToken = null;
HtmlImgToken imgToken = null;
currentToken = tokens[position];
while (currentToken != null)
{
textToken = currentToken as HtmlTextToken;
brToken = currentToken as HtmlBrToken;
beginSpanToken = currentToken as HtmlBeginSpanToken;
endSpanToken = currentToken as HtmlEndSpanToken;
beginDivToken = currentToken as HtmlBeginDivToken;
endDivToken = currentToken as HtmlEndDivToken;
imgToken = currentToken as HtmlImgToken;
if (textToken != null)
{
HtmlTextNode textNode = new HtmlTextNode();
textNode.Text = textToken.Text;
position++;
while (tokens.Count > position && (textToken = tokens[position] as HtmlTextToken) != null)
{
textNode.Text += textToken.Text;
position++;
}
parentNode.Children.Add(textNode);
}
else if (beginSpanToken != null)
{
HtmlSpanNode spanNode = new HtmlSpanNode();
position++;
GetAttributes(spanNode, beginSpanToken);
GetContents(spanNode, tokens, ref position);
if (tokens.Count < position || tokens[position] as HtmlEndSpanToken == null)
{
if (throwExceptions)
{
throw new Exception("Missing end span tag");
}
}
parentNode.Children.Add(spanNode);
position++;
}
else if (endSpanToken != null)
{
if (parentNode.GetType() == typeof(HtmlSpanNode))
{
return;
}
else
{
if (throwExceptions)
{
throw new Exception("Encountered closing span tag without matching open tag.");
}
else
{
position++;
}
}
}
else if (beginDivToken != null)
{
HtmlDivNode divNode = new HtmlDivNode();
position++;
GetAttributes(divNode, beginDivToken);
GetContents(divNode, tokens, ref position);
if (tokens.Count <= position || tokens[position] as HtmlEndDivToken == null)
{
if (throwExceptions)
{
throw new Exception("Missing end div tag");
}
}
parentNode.Children.Add(divNode);
position++;
}
else if (endDivToken != null)
{
if (parentNode.GetType() == typeof(HtmlDivNode))
{
return;
}
else
{
if (throwExceptions)
{
throw new Exception("Encountered closing div tag without matching open tag.");
}
else
{
position++;
}
}
}
else if (brToken != null)
{
HtmlBrNode brNode = new HtmlBrNode();
GetAttributes(brNode, brToken);
parentNode.Children.Add(brNode);
position++;
}
else if (imgToken != null)
{
HtmlImgNode imgNode = new HtmlImgNode();
GetAttributes(imgNode, imgToken);
parentNode.Children.Add(imgNode);
position++;
}
else
{
position++;
}
if (tokens.Count > position)
{
currentToken = tokens[position];
}
else
{
return;
}
}
}
private static void GetAttributes(HtmlNode htmlNode, HtmlToken htmlToken)
{
foreach (KeyValuePair<string, string> kvp in htmlToken.Attributes)
{
htmlNode.AddAttribute(kvp);
}
}
public static HtmlNode Parse(string text)
{
List<HtmlToken> tokens = Tokenize(text);
HtmlNode rootNode = Parse(tokens);
return rootNode;
//return Parse(Tokenize(text));
}
}
}

View File

@@ -0,0 +1,149 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<ProjectGuid>{A6FA0455-ACB5-4E80-9E58-6B79976AA717}</ProjectGuid>
<ProjectTypeGuids>{6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PlanB.Html</RootNamespace>
<AssemblyName>Plan B Html Parser</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<XnaFrameworkVersion>v3.1</XnaFrameworkVersion>
<XnaPlatform>Windows</XnaPlatform>
<XnaCrossPlatformGroupID>1aed1ad2-9777-46c5-92fe-ef987622475f</XnaCrossPlatformGroupID>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\x86\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE;WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<UseVSHostingProcess>false</UseVSHostingProcess>
<PlatformTarget>x86</PlatformTarget>
<XnaCompressContent>false</XnaCompressContent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\x86\Release</OutputPath>
<DefineConstants>TRACE;WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<UseVSHostingProcess>false</UseVSHostingProcess>
<PlatformTarget>x86</PlatformTarget>
<XnaCompressContent>true</XnaCompressContent>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Xna.Framework, Version=3.1.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d, processorArchitecture=x86">
<Private>False</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="Microsoft.Xna.Framework.Game, Version=3.1.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d, processorArchitecture=MSIL">
<Private>False</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="mscorlib">
<Private>False</Private>
</Reference>
<Reference Include="System">
<Private>False</Private>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml">
<Private>False</Private>
</Reference>
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
<Private>False</Private>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Nodes\HtmlBrNode.cs" />
<Compile Include="Nodes\HtmlDivNode.cs" />
<Compile Include="Nodes\HtmlImgNode.cs" />
<Compile Include="Nodes\HtmlSpanNode.cs" />
<Compile Include="Parser.cs" />
<Compile Include="Nodes\HtmlDocumentNode.cs" />
<Compile Include="Nodes\HtmlNode.cs" />
<Compile Include="Nodes\HtmlTextNode.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tokens\HtmlBeginDivToken.cs" />
<Compile Include="Tokens\HtmlBeginSpanToken.cs" />
<Compile Include="Tokens\HtmlBrToken.cs" />
<Compile Include="Tokens\HtmlEndDivToken.cs" />
<Compile Include="Tokens\HtmlEndSpanToken.cs" />
<Compile Include="Tokens\HtmlImgToken.cs" />
<Compile Include="Tokens\HtmlTextToken.cs" />
<Compile Include="Tokens\HtmlToken.cs" />
</ItemGroup>
<ItemGroup>
<NestedContentProject Include="Content\Content.contentproj">
<Project>730f03d9-cb96-43a9-88e3-a8687a66cf5e</Project>
<Visible>False</Visible>
</NestedContentProject>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
<Visible>False</Visible>
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
<Visible>False</Visible>
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Xna.Framework.3.1">
<Visible>False</Visible>
<ProductName>Microsoft XNA Framework Redistributable 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\Microsoft.Xna.GameStudio.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,10 @@
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "1"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}

View File

@@ -0,0 +1,31 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Plan B Html Parser")]
[assembly: AssemblyProduct("Plan B Html Parser")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("b8545a1e-c024-4eec-9d5e-a3e470e43671")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Tokens
{
public class HtmlBeginDivToken:HtmlToken
{
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Tokens
{
public class HtmlBeginSpanToken: HtmlToken
{
public override string ToString()
{
return "<span>";
}
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Tokens
{
public class HtmlBrToken: HtmlToken
{
public override string ToString()
{
return "<br/>";
}
}
}

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Tokens
{
public class HtmlEndDivToken: HtmlToken
{
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Tokens
{
public class HtmlEndSpanToken: HtmlToken
{
public override string ToString()
{
return "</span>";
}
}
}

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Tokens
{
public class HtmlImgToken: HtmlToken
{
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlanB.Html.Tokens
{
public class HtmlTextToken: HtmlToken
{
public string Text { get; set; }
public HtmlTextToken()
{
Text = String.Empty;
}
public HtmlTextToken(string str)
{
Text = str;
}
public override string ToString()
{
return Text ?? String.Empty;
}
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace PlanB.Html.Tokens
{
public class HtmlToken
{
public List<KeyValuePair<string, string>> Attributes { get; set; }
public HtmlToken()
{
Attributes = new List<KeyValuePair<string, string>>();
}
public override string ToString()
{
return String.Empty;
}
internal void AddAttributes(Match m)
{
Group attributeNameGroup = m.Groups["attributeName"];
Group attributeValueGroup = m.Groups["attributeValue"];
//int numAttributes = m.Groups["attributeName"].Captures.Count;
int numAttributes = attributeNameGroup.Captures.Count;
for (int i = 0; i < numAttributes; i++)
{
//KeyValuePair<string, string> attribute = new KeyValuePair<string, string>(m.Groups["attributeName"].Captures[i].ToString(), m.Groups["attributeValue"].Captures[i].ToString());
KeyValuePair<string, string> attribute = new KeyValuePair<string, string>(attributeNameGroup.Captures[i].ToString(), attributeValueGroup.Captures[i].ToString());
Attributes.Add(attribute);
}
}
}
}