0

I have a .out file which has xml content like this.

<header stub>
    <article type="audio">
        <addedDate>2010-03-11 05:11:57</addedDate>
        <thumbnail>http://fgsdfff/4588/thumbnail_9.jpg</thumbnail>
        <asset="blarga.mp3" addedDate="2009-01-07 01:48:37">
            <size>3289048</size>
            <duration>206000</duration>
            <mime_type>audio/mpeg</mime_type>
        </asset>
    </article>
</footer stub>
  1. I have to add <?xml version="1.0"?> and </xml> at the start of the xml and at the end respectively.
  2. I have to replace <header stub> and </footer stub> with <channel> and </channel> tags respectively.
  3. You might have noticed the XML is not well formed in the <asset> tag. It has to be like <asset url="blarga.mp3" addedDate="2009-01-07 01:48:37">. How do I add the url attribute?
  4. In the thumbnail tag, i have to remove _9 from the jpg's name.

And finally, i have to convert the .out to .xml file.

Please help me with these

5
  • 4
    That isn't XML content... at least, the sample you've given isn't Commented Jun 21, 2011 at 6:45
  • 2
    What exactly is your question? Commented Jun 21, 2011 at 6:45
  • ah better, helps if code is formatted. Commented Jun 21, 2011 at 6:46
  • I strongly suggest to fix the .out file generator instead of hacking around the invalid XML in the results. Commented Jun 21, 2011 at 7:02
  • Not sure you'd want to have the closing </xml> tag at the end. There is no opening <xml> tag. Commented Jun 21, 2011 at 7:16

2 Answers 2

1
$content = file_get_content OR mysql_query;//"YOUR XML CONTENT FROM FILE OR MYSQL";
$content = "<?xml version="1.0"?>" . $content . "</xml>";
$content = str_replace("<header stub>", "<channel>", $content);
$content = str_replace("</footer stub>", "</channel>", $content);
$content = str_replace("<asset=", "<asset url=", $content);
$content = str_replace("thumbnail_9.jpg", "thumbnail.jpg", $content);
Sign up to request clarification or add additional context in comments.

Comments

1

You can use DOMDocument class.

An example of its usage can be found here

2 Comments

I doubt that SimpleXML will be useful here because the content is not well-formed XML.
Yes, I figured that out as the question changed. Have modified my answer too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.