Work with XML, Schemas, DOM, PHP, etc.

I seem to be reading circles, or maybe I just donโ€™t understand some of the concepts here. I am processing a set of PHP template classes that previously used some fancy regular expressions to combine and duplicate documents and document areas, creating an output page. An example of my previous method (for completeness):

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

In any case, it works very well, but I really want to move it to the next level and realized that it would logically expand the markup, 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="Ymd H:i:s" /></h2> <p><zuq:var name="myText" format="maxLength" param="300" /></p> </div> </zuq:region> </div> 

I read W3 specifications and even W3Schools tutorials on various related technologies, such as XML Schema for writing template specifications. Obviously, I want everything to be well-formed and work in all the used namespaces. This will primarily be used with XHTML markup.

In any case, can anyone point me to a good read on understanding XML namespaces , constraints, and best practices for mixing namespaces , and, most importantly, I suppose working with PHP / DOM / XML . Are there any critical flaws in my approach that everyone can see? PHP doesn't seem to have a particularly powerful implementation for working with markup documents with names, either through DOMDocument (and siblings) or SimpleXML .

Any advice, suggestions for reading or criticism are welcome!


Edit: in case anyone is interested, elements from the zuq namespace should not be present during the output of the output, parsed and otherwise removed. However, in addition to the good practice of storing documents, I intend to take advantage of the markup present in the templates, so that administrators can quickly edit pages through the CMS WYSIWYG editor.

+4
source share
1 answer

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

As for XML processing with PHP with names, the DOM interface works very well. For example, you can getElementsByTagNameNS , you can lookupNamespaceURI , find the URI prefix specified in the prefix ...

In addition, the question seems incredibly subjective and vague, so if you want to edit it or post additional questions that will improve it, you may be able to get more specific help.

+2
source

Source: https://habr.com/ru/post/1333013/


All Articles