如何匹配两个 HTML 标签的内容?它们之间有多行字符串。 -AS3
我想匹配 标签内的所有内容...下面是我需要解析的示例。
<tr>
<td class="trow2 post_content ">
<div class="post_body" id="pid_">
This is <span style="font-style: italic;">just a test</span> message.<br />
With an image.<br />
[img]http://www.somesite.com/wp-content/something.jpg[/img]<br />
Blah blah <span style="font-weight: bold;">blah</span>.<br />
<br />
The quick brown fox jumps over the lazy <span style="text-decoration: underline;">dawg</span>.<br />
<br />
[video=youtube]http://www.youtube.com/watch?v=MbYZa4gTxzM[/video]<br />
<br />
<a href="mailto:[email protected]">asd</a><br />
<ul>
<li>item number 1</li>
<li>item nubmer 2<br />
</li></ul>
<br />
<div class="codeblock phpcodeblock"><div class="title">PHP Code:<br />
</div><div class="body"><div dir="ltr"><code><span style="color: #66CCFF"><?php </span><span style="color: #7AC07C">echo </span><span style="color: #FF99FF">'hello world'</span><span style="color: #7AC07C">; </span><span style="color: #66CCFF">?></span></code></div></div></div>
<br />
<div style="text-align: center;">i am centered.</div>
<div style="text-align: right;">i am not centered.</div>
</div>
<div class="post_meta" id="post_meta_">
</div>
</td>
</tr>
正如您所看到的,我故意在标签之间添加了一大堆内容。这是我需要帮助的部分。鉴于存在其他标签的方式,我如何检测上面指定的两个标签的内部。
这是在 Flash Builder 上的 AS3 中完成的。
I want to match all contents inside the <div class="post_body" id="pid_"></div> tags... A sample of what I need to parse is below.
<tr>
<td class="trow2 post_content ">
<div class="post_body" id="pid_">
This is <span style="font-style: italic;">just a test</span> message.<br />
With an image.<br />
[img]http://www.somesite.com/wp-content/something.jpg[/img]<br />
Blah blah <span style="font-weight: bold;">blah</span>.<br />
<br />
The quick brown fox jumps over the lazy <span style="text-decoration: underline;">dawg</span>.<br />
<br />
[video=youtube]http://www.youtube.com/watch?v=MbYZa4gTxzM[/video]<br />
<br />
<a href="mailto:[email protected]">asd</a><br />
<ul>
<li>item number 1</li>
<li>item nubmer 2<br />
</li></ul>
<br />
<div class="codeblock phpcodeblock"><div class="title">PHP Code:<br />
</div><div class="body"><div dir="ltr"><code><span style="color: #66CCFF"><?php </span><span style="color: #7AC07C">echo </span><span style="color: #FF99FF">'hello world'</span><span style="color: #7AC07C">; </span><span style="color: #66CCFF">?></span></code></div></div></div>
<br />
<div style="text-align: center;">i am centered.</div>
<div style="text-align: right;">i am not centered.</div>
</div>
<div class="post_meta" id="post_meta_">
</div>
</td>
</tr>
As you can see, I intentionally added a whole bunch of stuff in-between the tags. This was the part where I needed help for. How do I detect the insides of the two tags I specified above given the fact that there are other tags in their way.
This is done in AS3 on Flash Builder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的 HTML 是 XHTML,您可以使用 XPath 来解析并获取这些标记内的值。请参阅此问题在 Actionscript 中解析 XML/XHTML
If your HTML is XHTML, you can use XPath to parse and get the values inside those tags. See this question Parsing XML/XHTML in Actionscript