php - 有没有办法将 CSS 链接放入 php 动态生成的 XML 文件中?
问题描述
我已经成功地在 php 中使用 dom 动态生成了一个 xml 文件,但我不确定如何将 CSS 链接放入其中。
我需要 php 代码将 CSS 与自动生成的 XML 文件链接起来。
解决方案
要链接 XML 中的 CSS,您可以使用xml-stylesheet
处理指令。使用 DOMDocument 上的相应方法创建它,然后像任何其他节点一样附加/插入它。
$document = new DOMDocument();
$document->appendChild(
$document->createProcessingInstruction(
'xml-stylesheet', 'type="text/css" href="styles.css"'
)
);
$document->appendChild(
$document->createElement('example')
);
echo $document->saveXML();
输出:
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="styles.css"?>
<example/>
推荐阅读
- python - 如何找到迭代两个数组的时间?
- selenium-webdriver - 如何处理硒中网页的自动重定向
- linkedin - 用于检索消息的 LinkedIn API?
- pine-script - 职位管理策略?获利一半
- apache-spark - Spark 阶段花费的时间太长 - 2 个执行者完成“所有”工作
- python - 使用 Robot Framework 4.0 是否可以将值从 .body 输入和输出到 python 脚本和从 python 脚本到 .body 测试套件?
- pandas - 仅爬取第一页并将详细内容保存为 Python 中的数据框
- azure-ad-graph-api - 如何使用 Microsoft Graph API 阅读托管在本地 Exchange 服务器上的 Outlook 电子邮件?
- java - 如何修复 Eclipse 中的“构建期间发生错误”?
- python - RSA 中的十进制代码太大