承接 stanclik/to-xml 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

stanclik/to-xml

Composer 安装命令:

composer require stanclik/to-xml

包简介

A simple library to generate xml files

README 文档

README

An easy-to-use library for generating XML files.

MIT License

Installation

Install usign composer

  composer require stanclik/toxml

Usage/Examples

require 'vendor/autoload.php';
use \Stanclik\ToXml\ToXml;
use \Stanclik\ToXml\Blocks;

$xml = new ToXml([]);

// set document header
$xml->setHeaders(Blocks::header(['version' => '1.0', 'encoding' => Blocks::UTF_8]));
// set root element
$xml->root('offers', ['param' => 'foo']);
$xml->add(
    Blocks::tag('item', [ // set item
        Blocks::tag('name', [Blocks::content('Some item')]),
        Blocks::tag('description', [Blocks::content('Some description')]),
        Blocks::tag('attributes', [ // set nested elements
            Blocks::tag('some-attribute', [], ['params' => 'foo']),
            Blocks::tag('some-attribute', [], ['params' => 'foo']),
            Blocks::tag('some-attribute', [], ['params' => 'foo']),
        ])
    ])
);
// call method to render xml;
$xml->render();

// print xml as a string;
header('Content-type: application/xml');
$xml->print();

// return xml as a string
$xml->get();

Result:

<?xml version="1.0" encoding="UTF-8"?>
<offers param="foo">
    <item>
        <name>
            <![CDATA[ Some item ]]>
        </name>
        <description>
            <![CDATA[ Some description ]]>
        </description>
        <attributes>
            <some-attribute params="foo"/>
            <some-attribute params="foo"/>
            <some-attribute params="foo"/>
        </attributes>
    </item>
</offers>

Blocks

Header

Blocks::header([
    'version' => '1.0' // add header on start of the content
])

Tag

Blocks::tag(
    'tag-name' // tag name ex: <tag-name>
    [
        // nested tags
    ],
    [
        'param' => 'foo' // params ex: <tag-name params="foo">
    ]
)

Content

Blocks::content(
    'Lorem Ipsum' // content inside the element,
    true|false // wrap the content in CDATA tags
)

Raw

Blocks::raw(
    '<tag><!CDATA[some stuff]]>' // just add raw tag
)

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-03