是否在Java的URIResolver概念在C#和.NET的存在吗? [英] Does the Java URIResolver concept exist in C# and .NET?
问题描述
在爪哇XML转换包,有被称为一个的的URIResolver ,这是实现此接口,可以由处理器调用把一个URI用于文档(),XSL的对象:进口,或XSL:包括成源对象。
In the Java XML transformation package, there is a concept known as a URIResolver, which is "An object that implements this interface that can be called by the processor to turn a URI used in document(), xsl:import, or xsl:include into a Source object."
所以,如果您的XSL有一个这样的进口
So, if your XSL has an import like this
<xsl:import href="URI"/>
这可以让你把URI和其映射到的您所选择的来源 - 也许它来自于一个数据库,或者您想要映射的URI与另一个URI。这可能是有用的,因为你不能使用的xsl:在
XSL变量
:进口HREF
This allows you to take URI and map it to the Source of your choice - maybe it comes from a database, or maybe you want to map the URI to another URI. This can be useful, since you can't use an xsl:variable
in the xsl:import href
.
下面是一些示例的Java code,创建一个变压器做了改变。
Here is some sample Java code that creates a transformer and does a transform.
URIResolver uriResolver = new MyURIResolver(); // sample
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setURIResolver(uriResolver);
Transformer transformer = transformerFactory.newTransformer();
transformer.setURIResolver(uriResolver);
transformer.transform(xml, result);
请注意,有两个地方在code,其中的URIResolver使用:
Note, there are two places in the code where the URIResolver is used:
- 的TransformerFactory <一href="http://java.sun.com/webservices/docs/1.6/api/javax/xml/transform/TransformerFactory.html#setURIResolver%28javax.xml.transform.URIResolver%29"相对=nofollow> setURIResolver - 设置对象 期间所使用的默认 转型要解决的URI使用 文件(),XSL:进口,或 XSL:包括 。
- 变压器<一href="http://java.sun.com/webservices/docs/1.6/api/javax/xml/transform/Transformer.html#setURIResolver%28javax.xml.transform.URIResolver%29"相对=nofollow> setURIResolver - 设置 一个对象,将用于 解决文档()中使用的URI。
- TransformerFactory setURIResolver - "Set an object that is used by default during the transformation to resolve URIs used in document(), xsl:import, or xsl:include."
- Transformer setURIResolver - "Set an object that will be used to resolve URIs used in document()."
问题:是否有类似的概念到Java的URIResolver在C#和.NET
Question: Is there a similar concept to the Java URIResolver in C# and .NET?
推荐答案
是的,这就是所谓的 的XmlResolver
。
Yes, it's called XmlResolver
.
的XmlResolver
是的System.Xml
抽象之一,这意味着你可以在不同的API,如用它 XslCompiledTransform
,的XmlDocument
,的XmlReader
(通过 XmlReaderSettings
),等等。
XmlResolver
is one of System.Xml
abstractions, which means you can use it in various APIs, such as XslCompiledTransform
, XmlDocument
, XmlReader
(via XmlReaderSettings
), etc.
下面是它是如何工作的更深入,以及如何实施你自己的解析器。
Here's a more in-depth on how it works, and how you can implement your own resolver.
在默认情况下,这些不同的API使用 XmlUrlResolver
,它可以解决开始的URI 的http://
和文件://
。
By default, these various APIs use the XmlUrlResolver
, which can resolve URIs that start with http://
and file://
.
此外,为解决外部实体,可以覆盖默认的<一个href="https://msdn.microsoft.com/en-us/library/system.xml.xmlreader.resolveentity%28v=vs.110%29.aspx"相对=nofollow> ResolveEntity
方法上 的XmlReader
。
In addition, for resolving external entities, you can override the default ResolveEntity
method on XmlReader
.
这篇关于是否在Java的URIResolver概念在C#和.NET的存在吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!