PHP code example of idevman / xml-mapper

1. Go to this page and download the library: Download idevman/xml-mapper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

idevman / xml-mapper example snippets


Idevman\XmlMapper\XmlMapperServiceProvider::class,

'XmlMapper' => 'Idevman\XmlMapper\Support\Facades\XmlMapper',

$response = XmlMapper::mapTo([
    'from' => '/note@from',
    'to' => '/note@to',
    'heading' => '/note/content@heading',
    'body' => '/note/content@body',
    'raw' => '/note/raw',
    'simpleItem' => '/note/item',
    'simpleItemNumber' => '/note/item@number',
    'allItems' => '/note/item[]',
    'allItemsNumber' => '/note/item[]@number',
], $xml);

[
  "from" => "Tove"
  "to" => "Jani"
  "heading" => "Reminder"
  "body" => "Don't forget me this weekend!"
  "raw" => "Simple text"
  "simpleItem" => "Table"
  "simpleItemNumber" => "1"
  "allItems" => [
    0 => "Table"
    1 => "Chair"
    2 => "Door"
    3 => "Window"
  ]
  "allItemsNumber" => [
    0 => "1"
    1 => "2"
    2 => "3"
    3 => "4"
  ]
]

$response = XmlMapper::mapTo([
    'addressing[from,to]' => '/note[@from,@to]',
    'content[header,body]' => '/note/content[@heading,@body]',
    'items[sequence,value]' => '/note/item[][@number,@value]',
], $xml);

[
  "addressing" => [
    "from" => "Tove"
    "to" => "Jani"
  ]
  "content" => [
    "header" => "Reminder"
    "body" => "Don't forget me this weekend!"
  ]
  "items" => [
    [
      "sequence" => "1"
      "value" => "50"
    ],
    [
      "sequence" => "2"
      "value" => "40"
    ],
    [
      "sequence" => "3"
      "value" => "30"
    ],
    [
      "sequence" => "4"
      "value" => "60"
    ]
  ]
]