Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过xml,在标记处执行特定的操作_Php_Mysql_Xml_Dom - Fatal编程技术网

Php 通过xml,在标记处执行特定的操作

Php 通过xml,在标记处执行特定的操作,php,mysql,xml,dom,Php,Mysql,Xml,Dom,有人能给我指一下这方面的教程吗?我已经研究了一些关于Stackoverflow的类似问题,并在手册中研究了PHPDOM 我有一个XML文档,至少有两个特定的标记想要从我的数据库输出数据,否则仍然输出其他标记和其中的信息 所以我想在查询中获取信息,以便动态地自动插入主客场阵容 <root> <sometag>Some text here</sometag> <anothertag>Something else here</ano

有人能给我指一下这方面的教程吗?我已经研究了一些关于Stackoverflow的类似问题,并在手册中研究了PHPDOM

我有一个XML文档,至少有两个特定的标记想要从我的数据库输出数据,否则仍然输出其他标记和其中的信息

所以我想在查询中获取信息,以便动态地自动插入主客场阵容

<root>
    <sometag>Some text here</sometag>
    <anothertag>Something else here</anothertag>

    <Hometeam>Cardinals</Hometeam>
        <HomeLineup></HomeLineup> -- this would be database driven data

    <Awayteam>Giants</Awayteam>
        <AwayLineup></AwayLineup> -- this would be database driven data

    <yetmoretags>Other stuff</yetmoretags>

</root>

这里有一些文字

但是a)我不确定如何确保其他xml标记和内容被吐出 b)不确定如何加载这些文件或在什么时候输出

实际上,我正在制作一个包含一些其他内容的完整页面,php和javascript相关,我不确定在特定DOM标记中输出数据库内容的最佳方法

我查看了PHP DOM文档,了解了如何操作和查找特定标记,但不知道如何输出整个文档,尤其是在该文档中包含动态内容。

类似这样的模板:

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="xhtml xsl xs"> 

<xsl:output method="html" version="1.0" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" indent="no"/> 

  <!-- match and copy verbatim everything - unless there is another template for it -->
  <xsl:template match="@*|node()"> 
        <xsl:copy> 
            <xsl:apply-templates select="@*|node()"/> 
        </xsl:copy> 
  </xsl:template> 

  <xsl:template match="HomeLineup"> 
        <xsl:copy> 
            <!-- do something here --> 
        </xsl:copy> 
  </xsl:template> 

  <xsl:template match="AwayLineup"> 
        <xsl:copy> 
            <!-- do something here --> 
        </xsl:copy> 
  </xsl:template> 

</xsl:stylesheet>


注意:[1]匹配所有内容的模板-确保复制所有内容。[2] 其他模板将匹配您的特定标记。[3] 更改样式表和输出声明,以符合您的需求,并感谢回复。只是还没有机会看任何东西。我需要读一读,然后再给你回复。