1

I had an XML that I turned into an array to sort it, now I want to save it as an XML again. This would not be a problem if I didn't have the following: [caseid] => Array ( [#text] => 885470 ...

I need: <caseid> 885470 </caseid>

Writing the DOM has been fine for the fieldname "caseid", but the fieldvalue is an array titled "#text" that I cannot figure out how to parse.

I can't search google for "#" symbols, so searching has been pretty tough.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • 1
    Presumably you're doing this in a loop. You'd need to check each node's attributes array for a #text value. if it's present, you'll have to extract it, delete it from the array, and set it as the dom node's text content. – Marc B Aug 10 '11 at 20:18
  • #text is a string: var_dump shows the following `caseid array(1) { ["#text"]=> string(6) "885470" }` – IDLacrosseplayer Aug 10 '11 at 20:20
  • Marc, do you have an example of this? – IDLacrosseplayer Aug 10 '11 at 20:23
  • The fieldvalue is not an array titled "#text". – Lightness Races in Orbit Aug 10 '11 at 20:36
  • 1
    `#text` is what DOM returns when fetching the `nodeName` of a DOMText. For an explanation, see http://stackoverflow.com/questions/4598409/printing-content-of-a-xml-file-using-xml-dom/4599724#4599724 and http://stackoverflow.com/questions/4979836/noob-question-about-domdocument-in-php/4983721#4983721 – Gordon Aug 10 '11 at 20:40
  • Tomalak, I am totally new to PHP/XML (this is a volunteer project). When I type `print_r($array[0][caseid]);` I get `Array ([#text] => 885470)`...How should I read this? – IDLacrosseplayer Aug 11 '11 at 15:49
  • @Gordon: that is an excellent page. Thank you for the reference. I have narrowed it down to me improperly converting the XML to the array. One more step and I should hopefully have it! – IDLacrosseplayer Aug 11 '11 at 15:52

1 Answers1

0

I was able to access the number in the array by referencing it as a string. Stupid way to do it, but it works; the best solution would be to edit the array to xml conversion, but accessing array elements via strings worked too.

I was previously accessed array elements like so:

print_r($array[caseid][#text]); //<--Does not work with #
print_r($array[caseid]['#text']); //works 

Again, not the prettiest, but a viable workaround.