What is the use of static fields PI_ENABLE_OUTPUT_ESCAPING & PI_DISABLE_OUTPUT_ESCAPING and how can we use them?

我是研究僧i 提交于 2021-02-19 08:36:32

问题


I am new to jaxp and has no idea of using the above static fields and what they mean ?

Need its explanation along with examples.

Thanks in advance


回答1:


XSLT has a feature called "disable output escaping" that tells the serializer to output <a> as <a> whereas it would normally output &lt;a&gt;. This is a hack that is best avoided, for many reasons, one of which is that it requires a special side-channel for the transformation engine to communicate with the serializer (so the transformer can tell the serializer to switch doe on and off).

In JAXP, to allow one vendor's transformation engine to talk to another vendor's serializer, the protocol for passing these doe-on and doe-off requests is this pair of processing instructions.

You don't need this feature and you can safely ignore its existence. Never be tempted to imagine that just because a feature is there, you must be missing something if you never use it.




回答2:


(Disclaimer - I maintain the JDOM XML Library) - These PI's (ProcessingInstructions) are designed to indicate to XML outputting programs that they should break compatibility with the XML standard, and produce invalid XML.

Under certain conditions, this can be useful.

Here is a test-case in the JDOM test harness. It basically has input like (I have added some whitepsace to it to make it easier to see):

<root>
  &amp;
  <?javax.xml.transform.disable-output-escaping ?>
  &amp;&amp;
  <?javax.xml.transform.enable-output-escaping ?>
  &amp;
</root>

In the above example, we have valid XML. If you were to process this data through a system that recognizes the processing instrucitons, it should output (something like)

<root>
  &amp;
  &&
  &amp;
</root>

Note that this is no longer valid XML..... the & characters between the PI's have not been escaped correctly.

From a JDOM perspective, this is documented here in the javadoc

These instructions are normally used in XML Transformations to produce output that is 'pretty, and is not consumed by machines, but by people. Use it with caution.

Hope that gives you some insight.... all the best.



来源:https://stackoverflow.com/questions/16400200/what-is-the-use-of-static-fields-pi-enable-output-escaping-pi-disable-output-e

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!