matlab.io.xml.dom.ResourceIdentifier 类
包: matlab.io.xml.dom
说明
matlab.io.xml.dom.ResourceIdentifier
类的对象标识实体解析器要标识的资源类型。
如果您配置 matlab.io.xml.dom.Parser
对象以通过使用从 matlab.io.xml.dom.EntityResolver
类派生的类来解析实体,并且解析器遇到实体,则解析器会创建一个 matlab.io.xml.dom.ResourceIdentifier
对象。您可以在实体解析器的 resolveEntity
方法中访问 ResourceIdentifier
对象。使用 ResourceIdentifier
对象来确定实体的解析。
matlab.io.xml.dom.ResourceIdentifier
类是 handle
类。
属性
PublicId
— 资源的公共 ID
""
(默认) | 字符串标量
资源的公共 ID,指定为字符串标量。
属性:
GetAccess | public |
SetAccess | private |
GetObservable | true |
SetObservable | true |
SystemId
— 资源的系统 ID
""
(默认) | 字符串标量
资源的系统 ID,指定为字符串标量。
属性:
GetAccess | public |
SetAccess | private |
GetObservable | true |
SetObservable | true |
SchemaLocation
— 架构的位置
""
(默认) | 字符串标量
架构的位置,指定为字符串标量。
属性:
GetAccess | public |
SetAccess | private |
GetObservable | true |
SetObservable | true |
Namespace
— 要解析的实体的命名空间的 URI
""
(默认) | 字符串标量
要解析的实体的命名空间的 URI,指定为字符串标量。
属性:
GetAccess | public |
SetAccess | private |
GetObservable | true |
SetObservable | true |
BaseURI
— 资源的基本 URI
""
(默认) | 字符串标量
资源的基本 URI,指定为字符串标量。
属性:
GetAccess | public |
SetAccess | private |
GetObservable | true |
SetObservable | true |
方法
公共方法
getResourceIdentifierType |
|
getLocator | locObj = getLocator(thisRI) 以 matlab.io.xml.dom.Locator 对象形式返回实体引用的位置。 |
示例
解析 XML 实体
此示例创建一个实体解码器,配置解析器来使用该解码器,并解析包含实体引用的 XML 文件。
该示例使用下列文件:
chapter.xml
包含章节的标记。
<?xml version="1.0" encoding="UTF-8"?> <chapter><title color="red">Introduction</title></chapter>
book.xml
包含实体引用&chapter;
,并声明该实体的资源为chapter.xml
。
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE book [ <!ENTITY chapter SYSTEM "chapter.xml"> ]> <book> &chapter; </book>
BookEntityResolver
是抽象类matlab.io.xml.dom.EntityResolver
的子类。
classdef BookEntityResolver < matlab.io.xml.dom.EntityResolver properties BaseDir end methods function obj = BookEntityResolver(baseDir) obj@matlab.io.xml.dom.EntityResolver() obj.BaseDir = baseDir; end function res = resolveEntity(obj,ri) import matlab.io.xml.dom.ResourceIdentifierType if getResourceIdentifierType(ri) == ResourceIdentifierType.ExternalEntity res = fullfile(obj.BaseDir, ri.SystemID); end end end end
创建一个实体解析器作为 BookEntityResolver
类的实例。
import matlab.io.xml.dom.*
resolver = BookEntityResolver(pwd);
创建一个解析器,并将其配置为使用解码器。
p = Parser(); p.Configuration.EntityResolver = resolver;
将文件 book.xml
解析到一个 matlab.io.xml.dom.Document
对象中。
domDoc = parseFile(p,"book.xml");
要查看 chapter
实体是否已解析,请在文档中查找 chapter
元素节点。
nl = getElementsByTagName(domDoc,"chapter");
ch = node(nl,1)
ch = Element with properties: TagName: 'chapter' HasAttributes: 0 TextContent: 'Introduction' Children: [1x1 matlab.io.xml.dom.Element]
版本历史记录
在 R2021a 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)