使用 XML、模式、DOM、PHP 等

发布于 2024-10-08 10:59:34 字数 1603 浏览 0 评论 0原文

我似乎在绕圈子阅读,或者可能只是没有理解这里的一些概念。我正在重新设计一组 PHP 模板类,这些类以前使用一些奇特的正则表达式来组合和复制文档和文档区域,从而生成输出页面。我以前的方法的一个例子(为了完整性):

<div id="myId">
    <!-- {{ region:myRegion }} -->
        <div class="myClass">
            <h1>{{ var:myHeading }}</h1>
            <h2>{{ var:myDatetime format:datetime(Y-m-d H:i:s) }}</h2>
            <p>{{ var:myText format:maxLength(300) }}</p>
        </div>
    <!-- {{ region:myRegion }} -->
</div>

在逻辑上会扩展标记本身,变成类似:

<div id="myId">
    <zuq:region name="myRegion">
        <div class="myClass">
            <h1><zuq:var name="myHeading" /></h1>
            <h2><zuq:var name="myDatetime" format="datetime" param="Y-m-d H:i:s" /></h2>
            <p><zuq:var name="myText" format="maxLength" param="300" /></p>
        </div>
    </zuq:region>
</div>

无论如何,它工作得很好,但我真的想将它提升到一个新的水平,并认为这 我一直在阅读 W3 规范,甚至是有关各种相关技术的 W3Schools 教程,例如用于编写模板规范的 XML Schema。显然,我希望在所有使用的命名空间中保持一切格式良好且有效。主要是与 XHTML 标记混合使用。

无论如何,任何人都可以给我一些关于理解 XML 命名空间混合命名空间的限制和最佳实践的好读物,最重要的是我认为,与< PHP/DOM/XML。我的方法是否存在任何人都可以看到的严重缺陷? PHP 似乎没有特别强大的实现来处理命名空间标记文档,无论是通过 DOMDocument (和兄弟)还是 SimpleXML

任何建议,欢迎阅读材料建议或批评!


编辑:如果有人好奇,来自 zuq 命名空间的元素在输出渲染时不应该出现,已经被解析或以其他方式删除。然而,除了保持文档有效的良好实践之外,我还打算利用模板中存在的标记,以便通过 CMS WYSIWYG 编辑器,管理员可以快速编辑页面。

I appear to be reading in circles, or perhaps am simply not grasping some of the concepts here. I'm reworking a set of PHP template classes, that previously used some fancy regular expressions to combine and duplicate documents and regions of documents, producing an output page. An example of my previous method (for the sake of completeness):

<div id="myId">
    <!-- {{ region:myRegion }} -->
        <div class="myClass">
            <h1>{{ var:myHeading }}</h1>
            <h2>{{ var:myDatetime format:datetime(Y-m-d H:i:s) }}</h2>
            <p>{{ var:myText format:maxLength(300) }}</p>
        </div>
    <!-- {{ region:myRegion }} -->
</div>

Anyways, it works quite well, but I really want to move it up to the next level, and figured that would logically be extending the markup itself, becoming something like:

<div id="myId">
    <zuq:region name="myRegion">
        <div class="myClass">
            <h1><zuq:var name="myHeading" /></h1>
            <h2><zuq:var name="myDatetime" format="datetime" param="Y-m-d H:i:s" /></h2>
            <p><zuq:var name="myText" format="maxLength" param="300" /></p>
        </div>
    </zuq:region>
</div>

I've been reading the W3 specifications, and even the W3Schools tutorials on various relevant technologies, like XML Schema for writing the template specifications. Obviously I want to keep everything well formed and valid in all namespaces used. Primarily this will be used mixed with XHTML markup.

Anyways, can anyone point me towards some good reading on understanding XML namespaces, the limits and best practices of mixing namespaces, and most importantly I suppose, working with PHP/DOM/XML. Are there any critical flaws in my approach here that anyone can see? It doesn't appear that PHP has a particularly powerful implementation for working with namespaced markup documents, whether its through DOMDocument (and brethren) or SimpleXML.

Any advice, reading material suggestions, or criticism is welcomed!


Edit: In case anyone is curious, elements from the zuq namespace should not be present at the time of output rendering, having been parsed and otherwise removed. However, beyond the good practice of keeping documents valid, I intend on taking advantage of the markup present in the templates, so that via a CMS WYSIWYG editor, administrators can quickly edit pages.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风透绣罗衣 2024-10-15 10:59:34

命名空间实际上是一个非常简单的概念,但不知何故却被夸大了。请参阅http://www.xml.com/pub/a/1999/ 01/namespaces.html 有关 XML 命名空间的优秀教程。

至于从 PHP 处理命名空间 XML,DOM 接口工作得很好。例如,您可以getElementsByTagNameNS,您可以lookupNamespaceURI, 查找给定 URI 的前缀.. 除此之外,

这个问题感觉非常主观和模糊,所以如果您愿意编辑它或发布进一步的问题来完善它,也许您可​​以获得一些更具体的帮助。

Namespaces are really a very simple concept that somehow gets blown out of proportion. See http://www.xml.com/pub/a/1999/01/namespaces.html for a good tutorial on XML Namespaces.

As for dealing with namespaced XML from PHP, the DOM interface works very well. For example, you can getElementsByTagNameNS, you can lookupNamespaceURI, look up a given URI's prefix...

Beyond that, the question feels incredibly subjective and vague, so if you care to edit it or post further questions that refine it, perhaps you can get some more concrete help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文