有没有办法将一个代码片段嵌入到另一个代码片段中?
假设我有
- 代码段 A
- 代码段 B
其中 片段 A 包含 片段 B n 次 其中 n > 1。
现在我已将片段 B 的内容复制到片段 A 中。这样做的缺点是,每当我更改代码段 B 时,我都必须另外更改代码段 A。因此,我的问题是是否有某种语句可以将一个片段嵌入到另一个片段中?
例如
或类似的东西。
Let's assume that I have
- snippet A
- snippet B
where snippet A contains snippet B n times with n > 1.
Right now I have copied the content of snippet B into snippet A. This has the disadvantage, that whenever I change snippet B, I have to additionally change snippet A. Therefore, my question is whether there is some kind of statement to embed one snippet into another?
e.g.<externalsnippet src=".\snippetB.snippet" />
or something similar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用外部解析的通用实体来声明代码段 B 的实体引用,然后在代码段 A 中使用它 n 次。
当代码段 A 被解析时,实体引用将被扩展,并且片段 B 中的内容将包含在使用该实体的每个位置。
例如,假设您有一个名为 snipppetB.xml 的文件:
snippet A 的文件声明了一个名为
snippetB
引用的实体snippetB.xml 并使用了四次:解析 snippetA.xml 时,XML 内容将如下所示:
You could use an external parsed general entity to declare an entity reference for snippet B and then use it n number of times inside of snippet A.
When snippet A is parsed, the entity references will be expanded and the content from snippet B will be included at each spot where the entity was used.
For example, assume that you had a file called snipppetB.xml:
And a file for snippet A declared an entity called
snippetB
referencing snippetB.xml and used it four times:When snippetA.xml is parsed, the XML content would look like this: