skip to Main Content

I need to read this function and create an xml with the title, description and etc fields.
then the table.

    public function defineCustomTemplate()
    {
        $this->setNmfile(302444);
        $this->setNmoperation("CPTEVALITHAB");
        $this->setNmimport(302433);

        $customTemplate = array();
        $customTemplate[] = array('column' => 'nmfield01', 'term' => 103571, 'dataType' => 2, 'precision' => 50, 'description' => 213795, 'required' => 1);
        $customTemplate[] = array('column' => 'nmfield02', 'term' => 102213, 'dataType' => 2, 'precision' => 50, 'description' => 302440, 'required' => 1);
        $customTemplate[] = array('column' => 'nmfield03', 'term' => 302442, 'dataType' => 2, 'precision' => 50, 'description' => 302442, 'required' => 1);
        $customTemplate[] = array('column' => 'nmfield04', 'term' => 302443, 'dataType' => 2, 'precision' => 50, 'description' => 302443, 'required' => 1);

        return $customTemplate;
    }

this function appears in several classes of the project and I would like to capture everywhere it is displayed and create the xml.

can someone help me?

2

Answers


  1. You can use the SimpleXMLElement class in PHP to create an XML document with the data from the defineCustomTemplate() function.

    Login or Signup to reply.
  2. approximate solution without fields hardcoding

        $sxml = new  SimpleXMLElement(('<?xml version="1.0" encoding="utf-8"?><file></file>'));
        $sxml->addAttribute('filename', $Nmfile);
    
        $operation = $sxml->addChild('operations');
        $operation->addAttribute('opname', $Nmoperation);
    
        foreach ($customTemplate as $key => $item) {
            $serverKeys = array_keys($item);
            $import = $operation->addChild('import');
            $import->addAttribute('import_id', $Nmimport);
    
            foreach ($serverKeys as $i => $name) {
                $ops = $import->addChild($name);
                $ops->addAttribute($name,$item[$name]);
           }
        }
    
        var_dump($sxml->asXML());
    

    output template:

    <?xml version="1.0" encoding="utf-8"?>
    <file filename="302444">
        <operations opname="CPTEVALITHAB">
            <import import_id="0">
                <column column="nmfield02"/>
                ...
            </import>
    
        </operations>
    </file>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search