0

I have sudo string in a sort of xml format which i want to convert to xml in php. Which I then want to grab the imaware which contains date string in different formats and convert to appropriate date.

sudo string

<IMAware>
09-03-2016 05:28
</IMAware>

<NextUpdate>
</NextUpdate>

<ETR>
</ETR>

<SMS>
text
</SMS>

<Summary>
text
</Summary>

<Impact>
text
</Impact>

<Plan>
</Plan>

<Resolution>
text
</Resolution>

<Complete>
text
</Complete>

<Timeline>
text
</Timeline>

<Crisis>
</Crisis>

So far I have the following

for ($i = 0; $i < count($dbData); $i++) {
            try {
                print_r(trim($dbData[$i]['INCIDENT_NOTES']));
                $xml = simplexml_load_string (trim($dbData[$i]['INCIDENT_NOTES']));
                print_r($xml);
            } catch (Exception $e) { 
                echo $e; 
            }

            /*$items = $xml->xpath(item);

            foreach($items as $item) {
                echo $item['title'], ': ', $item['description'], "\n";
            }*/
        }

This fails with

Warning: simplexml_load_string(): Entity: line 5: parser error : Extra content at the end of the document in /var/SP/oiadm/docroot/dev/maskella/common/api/Api.class.php on line 1444

Do I need to enclose with<?xml version='1.0'?> <document></document>?

Date formats which I have are

21-02-2016 20:14

Date/Time: 09/02 - 15:40

Date: 08/02 - 11:50

shorif2000
  • 2,582
  • 12
  • 65
  • 137
  • 2
    In the example you have complete xml? If it is, yes you have to wrap the string in ``. `` is not mandatory for your example. – fusion3k Mar 10 '16 at 14:55

1 Answers1

1

Yes, the xml doc will need the header, and will also need a root element which encapsulates the elements from your sudo example.

See What is the correct format to use for Date/Time in an XML file for appropriate date formats in XML.

Community
  • 1
  • 1
J Burnett
  • 2,410
  • 1
  • 13
  • 9