我的名字是Rithy.
我不知道如何在xml中添加新节点或元素之前添加新行.
我的PHP:
$dom = new DOMDocument();
$dom->formatOutput = true;
$dom->preserveWhiteSpace = true;
$dom->load($xml_file);
$body = $dom->getElementsByTagName('body')->item(0);
$newelement_seg = $dom->createElement('seg');
$data = $dom->createTextNode(" text 2 ");
$newelement_seg->appendChild($data);
$body->appendChild($newelement_seg);
$dom->save($xml_file);
Run Code Online (Sandbox Code Playgroud)
XML在添加新子项之前:
<?xml version="1.0" encoding="UTF-8"?>
<body>
<seg>
text 1
</seg>
</body>
</xml>
Run Code Online (Sandbox Code Playgroud)
附加新子后的XML:
<?xml version="1.0" encoding="UTF-8"?>
<body>
<seg>
text 1
</seg>
<seg>
text 2
</seg>
</body>
</xml>
Run Code Online (Sandbox Code Playgroud)
但我想要:
<?xml version="1.0" encoding="UTF-8"?>
<body>
<seg>
text 1
</seg>
<seg>
text 2
</seg>
</body>
</xml>
<hr/>
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我有配置问题或magento永远不会运行我的模块的SQL安装/更新脚本的其他东西!
我使用magento-1.4.1.0
这是我的结构文件夹和文件:
\app\code\local\RN\ShortUrl
\app\code\local\RN\ShortUrl\Block\ShortUrl.php
\app\code\local\RN\ShortUrl\controllers\IndexController.php
\app\code\local\RN\ShortUrl\controllers\UController.php
\app\code\local\RN\ShortUrl\etc\config.xml
\app\code\local\RN\ShortUrl\Helper\Url.php
\app\code\local\RN\ShortUrl\Model\ShortUrl.php
\app\code\local\RN\ShortUrl\Model\Mysql4\ShortUrl.php
\app\code\local\RN\ShortUrl\Model\Mysql4\ShortUrl\Collection.php
\app\code\local\RN\ShortUrl\Model
\app\code\local\RN\ShortUrl\Model\Mysql4
\app\code\local\RN\ShortUrl\Model\Mysql4\ShortUrl
\app\code\local\RN\ShortUrl\sql\rn_shorturl_setup\mysql4-install-0.1.0.php
Run Code Online (Sandbox Code Playgroud)
以下是内容\app\etc\modules\RN_ShortUrl.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<RN_ShortUrl>
<active>true</active>
<codePool>local</codePool>
</RN_ShortUrl>
</modules>
</config>
Run Code Online (Sandbox Code Playgroud)
以下是内容\app\code\local\RN\ShortUrl\etc\config.xml:
<?xml version="1.0"?>
<config>
<modules>
<RN_ShortUrl>
<version>0.1.0</version>
</RN_ShortUrl>
</modules>
<frontend>
<routers>
<shorturl>
<use>standard</use>
<args>
<module>RN_ShortUrl</module>
<frontName>shorturl</frontName>
</args>
</shorturl>
</routers>
<layout>
<updates>
<shorturl>
<file>shorturl.xml</file>
</shorturl>
</updates>
</layout>
</frontend>
<global>
<blocks>
<rn_shorturl>
<class>RN_ShortUrl_Block</class>
</rn_shorturl>
</blocks>
<rewrite>
<rn_shorturl>
<from>#^/u/(.*)#</from>
<to>/shorturl/u/redirect/key/$1</to>
</rn_shorturl>
</rewrite>
<models>
<shorturl>
<class>RN_ShortUrl_Model</class>
<resourceModel>shorturl_mysql4</resourceModel>
</shorturl>
<shorturl_mysql4>
<class>RN_ShortUrl_Model_Mysql4</class>
<entities>
<shorturl> …Run Code Online (Sandbox Code Playgroud)