网页可以包含 XML 内容,而后者又可以包含 URL。需要重写的 XML 内容分为以下两类:
本规则用于重写标记元素的 PCDATA 或 CDATA。
本节分为下列各小部分:
<TagText tag="tagName" [attributePatterns="attribute_patterns_for_ this_tag" source="*"]/>
其中
tagName 是标记的名称
attributePatterns 是与该标记相应的属性及其值模式(可选项,指该标记根本无任何属性)
source 是该 xml 文件的 URI(可选项,默认值是 *,指任何 xml 页)
假定页的基 URL 为:
http://abc.sesta.com/test/rewriter/test1/xml/page.html
页内容
<xml> <Attribute name="src">test.html</attribute> <attribute>abc.html</attribute> </xml>
规则
<TagText tag="attribute" attributePatterns="name=src"/>
输出
<xml> <Attribute name="src">gateway-URL/ http://abc.sesta.com/test/rewriter/test1/ xml/test.html</attribute><attribute>abc.html</attribute> </xml>
描述
页内容的第一行包含属性示例。页内容中的第二行不包含具有属性呼叫名称且属性名称值为 src 的属性,因此不会进行任何重写。要重写该属性,也需要有 <TagText tag="attribute"/>
XML 属性规则与 HTML 的属性规则类似。二者的区别在于,XML 的属性规则区分大小写,而 HTML 属性规则不区分大小写。这同样是因为 XML 中内置了对大小写的敏感性而 HTML 中则没有。
重写器会基于属性名称来转换属性值。
本节分为下列各小部分:
<Attribute name="attributeName " [tag="*" type="URL" valuePatterns="*" source="*"]/>
其中
attributeName 是属性的名称(强制项)
tag 是该属性所在标记的名称(可选项,默认值是 *,指任何标记)
valuePatterns 参见在规则中使用模式匹配
source 是该 XML 页的 URI(可选项,默认值是 *,指在任何 XML 页中)
假定页的基 URL 为:
http://abc.sesta.com/test/rewriter/test1/xml/page.html
页内容
<xml> <baseroot href="/root.html"/> <img href="image.html"/> <string href="1234|substring.html"/> <check href="1234|string.html"/> </xml>
规则
<Attribute name="href"tag="check" valuePatterns="1234|"/>
输出
<xml> <baseroot href="/root.html"/><img href="image.html"/> <string href="1234|substring.html"/><check href="1234| gateway-URL /http://abc.sesta.com/test/rewriter/test1/xml/string.html"/></xml>
描述
在上述示例中,只会重写第四行,因为它满足规则中指定的所有条件。参见在规则中使用模式匹配。