English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Is there anyway to achieve the following with less complexity?

I have some HTML that i need to rebuild. The problem is the HtmlParser currently being used is incapable of handling nested tags with horizontal alignment set differently. So for instance, If i have a DIV align=center and within it a DIV align=right, the parser will basically treat the entire block as centered (the align=right was dropped).

How do i go about parsing the following to go from:




TestRight


TestCenter2


TO



TestRight



TestCenter2

2007-06-04 05:31:38 · 3 answers · asked by zerohourx 1 in Computers & Internet Programming & Design

The provided HTML is only a simplified example. In production this can be many layers deep.

2007-06-04 05:32:51 · update #1

Unfortunately i still need to pass in the HTML into the parsing engine, but so that i can have it output correctly i need to modify the original HTML string before passing to the parser in such a way to remove nesting but somehow retain the formatting. Thats what iw as trying to achieve above. I just need some C# (or other) code to achieve it.

2007-06-04 05:35:36 · update #2

Added more details to CodePrject: http://www.codeproject.com/script/comments/forums.asp?forumid=1649&select=2066175&df=100&msg=2066175

2007-06-04 06:09:48 · update #3

3 answers

Ideally the parser should be able to handle nested tags with different style information. It is very difficult to come up with what you are saying considering that your request is true for all HTML elements.

It would help out if you can tell what are you trying to achieve with parser.

If it cannot handle it then this is what you should do....

1) Try and make all elements to be top level children (all div's should be direct children of body)

2) If you have instances where one div needs to be inside another, then you have to relative positioning and indexing to reflect the desired layout.

2007-06-04 05:45:35 · answer #1 · answered by rave27 2 · 0 0

There is nothing wrong with what you are trying to do. You just aren't doing it in correct XHTML style. You need quotes in the code, and some other things. Yahoo won't let me enter it correctly, but you basically need your HTML to be XHTML 1.0-compliant or ASP.Net will choke on it.

I'm assuming you are using ASP.Net. There is a lot of missing information in your question. This is a better question for a forum where you can have some discussion. Join CodeProject and shoot me an email when you post your question.

http://www.codeproject.com/ - best MS programming forum on the web. They have a good collection of articles too.

2007-06-04 12:42:30 · answer #2 · answered by polly_peptide 5 · 0 0

Use CSS! In the section place:


...then where you had your code try


...right-aligned stuff...

...centered stuff...

2007-06-04 12:49:01 · answer #3 · answered by fjpoblam 7 · 0 0

fedest.com, questions and answers