如何使用Jumony Core实现如下需求

何小宝 发布于 2013/12/09 15:24
阅读 567
收藏 0

问题是这样的。
有这样一段HTML字符串.
我需要获取Col的标签里的宽度值(可能是style='width:90px' 也可能直接是'width=90px')
替换到对应列的Td宽度.
难点1 上司要求不能转换成XML(这个已经实现了,考虑通用性)
难点2 table可能嵌套 其实说起来不复杂 逻辑还是有点绕的。


如果各位高手时间充足 不妨试试 练练手的同时 也帮为开辟一下例子或者思路。我正在试着实现
结果困扰我2天了 只实现了再没有嵌套Table下的替换 悲剧。
还要考虑colspan的问题。

转换之前 字符串

<table width='100%' border='1'>
           <col width='100px'>
           <tr>
                <td colspan='2'>
                    <table width='100%' border='1'>
                        <col />
                        <col width='91px' />
                        <col width='92px' />
                        <tr>
                            <td align='left'>
                                ISBN
                            </td>
                            <td align='left'>
                                Title
                            </td>
                            <td align='right'>
                                Price
                            </td>
                            <td align='right'>
                                AAA
                            </td>
                        </tr>
                        <tr>
                            <td align='left'>
                                3476896
                            </td>
                            <td align='left'>
                                My first HTML
                            </td>
                            <td align='right'>
                                $53
                            </td>
                            <td align='right'>
                                BB
                            </td>
                        </tr>
                        <tr>
                            <td align='left'>
                                3476897
                            </td>
                            <td align='left'>
                                My second HTML
                            </td>
                            <td align='right'>
                                $56
                            </td>
                            <td align='right'>
                                CC
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
 
转换之后是
 
<table width='100%' border='1'>
           <tr>
                <td colspan='2' width='100px' >
                    <table width='100%' border='1'>
                        <tr>
                            <td align='left'>
                                ISBN
                            </td>
                            <td align='left' width='91px'>
                                Title
                            </td>
                            <td align='right' width='92px'>
                                Price
                            </td>
                            <td align='right'>
                                AAA
                            </td>
                        </tr>
                        <tr>
                            <td align='left' >
                                3476896
                            </td>
                            <td align='left' width='91px'>
                                My first HTML
                            </td>
                            <td align='right' width='92px'>
                                $53
                            </td>
                            <td align='right'>
                                BB
                            </td>
                        </tr>
                        <tr>
                            <td align='left'>
                                3476897
                            </td>
                            <td align='left' width='91px'>
                                My second HTML
                            </td>
                            <td align='right' width='92px'>
                                $56
                            </td>
                            <td align='right'>
                                CC
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
 
使用c# 代码实现  不考虑JS JQ. 不好意思 希望各位不吝赐教

加载中
返回顶部
顶部