PHP Classes

File name in XML tag

Recommend this page to a friend!

      DOMIT XML parser  >  All threads  >  File name in XML tag  >  (Un) Subscribe thread alerts  
Subject:File name in XML tag
Summary:Get file path as string from xml to open file
Date:2007-05-29 05:05:34
Update:2007-05-29 05:50:20

  1. File name in XML tag   Reply   Report abuse  
Artem - 2007-05-29 05:05:34
Hello! It seems that to post messages in this forum is wrong way to decide your question, becaus anyone have answered previuos person :). But i decided to try :).

So. DOMIT is the real good thing for working with xml as DOM. But i have some trubles with it.
Well i have XML file like this:

<artical xml:id="2">
<title>Some title</title>
<anounce>Some anounce</anounce>

So i have problem to open file after getting string from <file> node content.
//..getting <file> node as $fileNode
$filename = $fileNode->firstChild->toString();
$fp = fopen( $filename, 'w' ); // and in this code warrning appears "can not open stream" $filename have wrong string format, i think.

What will i have to do to get right string with filename?

I`m thinking about such way as to save file path as attribute of <file>, but it`s not very good for my xml.

  2. Re: File name in XML tag   Reply   Report abuse  
John Heinstein - 2007-05-29 05:30:53 - In reply to message 1 from Artem

You could try putting the file name node in a CDATA section:


This will treat the contents of the node as plain text.


  3. Re: File name in XML tag   Reply   Report abuse  
Artem - 2007-05-29 05:50:20 - In reply to message 2 from John Heinstein
Thanks a lot!!! :) and one more question. If i want to save html in my xml of prev. example. I have to keep my html in CDATA tags too, have`n i?
Like this:
<content><![CDATA[some html]]</content>

ANd i can to get html by this way:

$html = $conten->firstChild->toString();

Is it right?