本文整理汇总了PHP中xml类的典型用法代码示例。如果您正苦于以下问题:PHP xml类的具体用法?PHP xml怎么用?PHP xml使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了xml类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFormElement
function getFormElement($id)
{
if ($e = $this->query('form' . ($id ? '[@id="' . $id . '"]' : null))->item(0)) {
$xml = new xml(null, null, false);
return $xml->appendChild($xml->importNode($e));
}
}
示例2: settings
function settings($action)
{
global $_out, $_struct;
if (($xml = $this->getDataXML()) && ($e = $xml->getElementById('settings'))) {
$form = new form($e);
$form->replaceURI(array('MODULE' => $this->getId(), 'SECTION' => $this->getSection()->getId(), 'PATH_DATA_FILE_CLIENT' => ABS_PATH_DATA_CLIENT . ap::id($this->getSection()->getId()) . '.xml', 'PATH_DATA_FILE_AP' => ABS_PATH_DATA_AP . ap::id($this->getSection()->getId()) . '.xml'));
if ($ff = $form->getField('section')) {
apSectionEdit::seclist(ap::getClientstructure()->de(), $ff, $ar = array());
}
switch ($action) {
case 'update':
case 'apply_update':
$form->save($_REQUEST);
break;
case 'edit':
if (($id = param('section')) && ($sec = $_struct->getSection($id)) && ($modules = $sec->getModules())) {
$xml = new xml(null, 'modules', false);
foreach ($modules as $m) {
$xml->de()->appendChild($xml->importNode($m->getRootElement(), false));
}
ap::ajaxResponse($xml);
}
break;
}
$form->load();
$_out->addSectionContent($form->getRootElement());
$this->addTemplate('tpl.xsl');
}
}
示例3: query
function query($args, $document)
{
$this->validate($args);
$sql = $this->datasource->get();
$xml = new xml();
$this->single() or $sql->begin();
$n = 0;
foreach ($this->body as $query) {
if ($rows = $sql->query($this->apply($query, $args))) {
$root = $xml->element($this->root[$n]);
$xml->append($root);
foreach ($rows as $row) {
$item = $xml->element($this->item[$n]);
$root->append($item);
foreach ($row as $name => $value) {
$node = $this->transform($xml, $name, $value);
$item->append($node);
}
}
++$n;
}
}
if (!$this->empty && $xml->blank()) {
$this->single() or $sql->rollback();
runtime_error('SQL procedure returned empty result: ' . $this->mangled());
} else {
$this->single() or $sql->commit();
}
return $document ? $xml : $xml->evaluate('/*[position() = 1]/*[position() = 1]/*[position() = 1]/text()');
}
示例4: XML_unserialize
function XML_unserialize($xml)
{
$xml_parser = new xml();
$data = $xml_parser->parse($xml);
$xml_parser->destruct();
return $data;
}
示例5: run
function run()
{
global $_out, $_sec;
if (ap::isCurrentModule($this)) {
ap::addMessage($this->getMessage());
if ($form = $this->getForm()) {
$form->replaceURI(array('ID' => $_sec->getId(), 'MD' => $this->getId(), 'PARENT' => $this->getSection()->GetParent()->getId()));
switch ($action = param('action')) {
case 'save':
$values = $this->initImages($form, true);
$values = array_merge($_REQUEST, $values);
$form->save($values);
$this->updateImagesSize($form);
$this->redirect('save_ok');
break;
case 'fileinfo':
if (($path = urldecode(param('path'))) && ($f = ap::getFileInfo($_SERVER['DOCUMENT_ROOT'] . $path))) {
$f['path'] = $path;
$xml = new xml(null, 'file', false);
foreach ($f as $tagName => $value) {
$xml->de()->appendChild($xml->createElement($tagName, null, $value));
}
ap::ajaxResponse($xml);
}
vdump('Error file not found ' . $path);
break;
}
$this->initImages($form, false);
$form->load();
$_out->elementIncludeTo($form->getRootElement(), '/page/section');
} else {
throw new Exception('Form not found', EXCEPTION_XML);
}
}
}
示例6: xml
function xml()
{
$xml = new xml();
foreach ($this->children as $child) {
$xml->append(self::node($xml, $child));
}
return $xml;
}
示例7: getSiteInfo
function getSiteInfo()
{
$xml = new xml();
$xml->dd()->appendChild($xml->importNode($this->de()));
$ns = $xml->query('/site/mysql | /site/users');
foreach ($ns as $n) {
$n->parentNode->removeChild($n);
}
return $xml;
}
示例8: get
function get($alias)
{
$alias .= ':' . $this->language;
if (isset($this->local[$alias])) {
return $this->local[$alias]->xml();
} else {
$xml = new xml();
$xml->append($xml->text("[Alias not found: {$alias}]"));
return $xml;
}
}
示例9: install
function install()
{
$xml_data = new xml(PATH_MODULE . $this->getName() . '/data.xml');
$xml_sec = $this->getSection()->getXML();
$ar = array('form_edit', 'form_add', 'banner_list');
foreach ($ar as $id) {
if (($e = $xml_data->query('//*[@id="' . $id . '"]')->item(0)) && !$xml_sec->evaluate('count(./*[@id="' . $id . '"])', $this->getRootElement())) {
$xml_sec->elementIncludeTo($e, $this->getRootElement());
}
}
$xml_sec->save();
return true;
}
示例10: __construct
function __construct(xml $xml, $tagName = null)
{
global $_struct;
if (!$tagName) {
$tagName = 'modules';
}
if ($modules = $xml->query($query = '/*/' . $tagName)->item(0)) {
} else {
$modules = $xml->de()->appendChild($xml->createElement($tagName));
}
parent::__construct($modules, 'module');
$this->keyAttribute = 'id';
$this->setStructure($_struct);
}
示例11: action_edit_field
public function action_edit_field()
{
$field_id = $this->request->param('options');
xml::to_XML(array('field' => array('@id' => $field_id, '$content' => User::get_data_field_name($field_id))), $this->xml_content);
if (count($_POST) && isset($_POST['field_name'])) {
$post = new Validation($_POST);
$post->filter('trim');
$post->rule('Valid::not_empty', 'field_name');
if ($post->validate()) {
$post_values = $post->as_array();
if ($post_values['field_name'] != User::get_data_field_name($field_id) && !User::field_name_available($post_values['field_name'])) {
$post->add_error('field_name', 'User::field_name_available');
}
}
// Retry
if ($post->validate()) {
$post_values = $post->as_array();
User::update_field($field_id, $post_values['field_name']);
$this->add_message('Field ' . $post_values['field_name'] . ' updated');
$this->set_formdata(array('field_name' => $post_values['field_name']));
} else {
$this->add_error('Fix errors and try again');
$this->add_form_errors($post->errors());
$this->set_formdata(array_intersect_key($post->as_array(), $_POST));
}
} else {
$this->set_formdata(array('field_name' => User::get_data_field_name($field_id)));
}
}
示例12: parse_childnodes
public static function parse_childnodes($element)
{
$tree = array();
// Loop Child nodes
foreach ($element->childNodes as $item) {
// Text Nodes
if ($item->nodeName == '#text') {
// Only Add Ones that are not empty
if (!empty($item->nodeValue) and !preg_match('/^([ \\t\\n\\r]+)$/', $item->nodeValue)) {
$tree[] = array('type' => 'text', 'value' => $item->nodeValue);
}
} else {
$i = array('type' => 'node', 'name' => $item->nodeName, 'value' => $item->nodeValue);
// Node Children
if (!empty($item->childNodes)) {
$x = xml::parse_childnodes($item);
if (!empty($x)) {
$i['children'] = $x;
}
}
$a = array();
// Node Attributes
if (!empty($item->attributes)) {
foreach ($item->attributes as $attr) {
$a[$attr->name] = $attr->value;
}
}
if (!empty($a)) {
$i['attributes'] = $a;
}
$tree[] = $i;
}
}
return $tree;
}
示例13: view
public function view() {
global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
$diff = $wgRequest->getVal( 'diff' );
$diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
if ( $this->mTitle->getNamespace() != NS_TIMEDTEXT || ( isset( $diff ) && $diffOnly ) ) {
return parent::view();
}
$titleParts = explode( '.', $this->mTitle->getDBKey() );
$srt = array_pop( $titleParts );
$lanugaeKey = array_pop( $titleParts );
$videoTitle = Title::newFromText( implode('.', $titleParts ), NS_FILE );
// Look up the language name:
$languages = Language::getTranslatedLanguageNames( 'en' );
if( isset( $languages[ $lanugaeKey ] ) ) {
$languageName = $languages[ $lanugaeKey ];
} else {
$languageName = $lanugaeKey;
}
// Set title
$wgOut->setPageTitle( wfMsg('mwe-timedtext-language-subtitles-for-clip', $languageName, $videoTitle) );
// Get the video with with a max of 600 pixel page
$wgOut->addHTML(
xml::tags( 'table', array( 'style'=> 'border:none' ),
xml::tags( 'tr', null,
xml::tags( 'td', array( 'valign' => 'top', 'width' => self::$videoWidth ), $this->getVideoHTML( $videoTitle ) ) .
xml::tags( 'td', array( 'valign' => 'top' ) , $this->getSrtHTML( $languageName ) )
)
)
);
}
示例14: executeAction
public function executeAction($params)
{
$eslCon = freeswitch_callmanager_Driver::getESL();
try {
$responsestr = $eslCon->sendRecv('api show channels as xml')->getBody();
} catch (ESLException $e) {
if (strpos($e->getMessage(), 'Not connected')) {
echo '<div class="error">Unable to connect to the switch console. This usually means that mod_event_socket is not running, or that the password that you entered during the setup process has changed. The error message was:<br>' . $e->getMessage() . '</span>';
exit;
} else {
throw $e;
}
}
if (trim($responsestr) == '0 total.' || trim($responsestr) == '+OK' || trim($responsestr) == '<result row_count="0"/>') {
return array();
}
if (substr(trim($responsestr), 0, 4) == '-ERR') {
$this->_throwError($responsestr);
}
$channelStatus = xml::xmlstrtoarr($responsestr);
if (count($channelStatus) == 0) {
return $channelStatus;
} else {
if (isset($channelStatus['row']['uuid'])) {
return array($channelStatus['row']);
} else {
return $channelStatus['row'];
}
}
}
示例15: toXml
/**
* The main function for converting to an XML document.
* Pass in a multi dimensional array and this recrusively loops through and builds up an XML document.
*
* @param array $data
* @param string $rootNodeName - what you want the root node to be - defaultsto data.
* @param SimpleXMLElement $xml - should only be used recursively
* @return string XML
*/
public static function toXml($data, $rootNodeName = 'data', $xml = null)
{
// turn off compatibility mode as simple xml throws a wobbly if you don't.
if (ini_get('zend.ze1_compatibility_mode') == 1) {
ini_set('zend.ze1_compatibility_mode', 0);
}
if ($xml == null) {
$xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><{$rootNodeName} />");
}
// loop through the data passed in.
foreach ($data as $key => $value) {
// no numeric keys in our xml please!
if (is_numeric($key)) {
// make string key...
$key = "unknownNode_" . (string) $key;
}
// replace anything not alpha numeric
$key = preg_replace('/[^a-z]/i', '', $key);
// if there is another array found recrusively call this function
if (is_array($value)) {
$node = $xml->addChild($key);
// recrusive call.
xml::toXml($value, $rootNodeName, $node);
} else {
// add single node.
$value = htmlentities($value);
$xml->addChild($key, $value);
}
}
// pass back as string. or simple xml object if you want!
return $xml->asXML();
}