0

I'm trying to read below xml from PHP and return empty. What I'm doing wrong?

XML

<?xml version="1.0" encoding="utf-8"?>
<page>
  <settings>
    <ss_pageRef><![CDATA[1]]></ss_pageRef>
    <ss_pageType><![CDATA[juicebox]]></ss_pageType>
    <ss_navName><![CDATA[Gallery]]></ss_navName>
    <ss_navWeight><![CDATA[1]]></ss_navWeight>
    <ss_navShow><![CDATA[true]]></ss_navShow>
    <ss_indexShow><![CDATA[true]]></ss_indexShow>
    <ss_parentPage><![CDATA[0]]></ss_parentPage>
    <ss_pageTitle><![CDATA[New gallery page]]></ss_pageTitle>
    <ss_pageDescription><![CDATA[This is gallery one]]></ss_pageDescription>
    <ss_pageBody><![CDATA[<p>Enter page body text here.</p>]]></ss_pageBody>
    <galleryTitle><![CDATA[]]></galleryTitle>
  </settings>
</page>

PHP

$galleries = simplexml_load_file("../gallery/page.xml") or die ("no gallery found");

print_r($galleries);

echo $galleries->ss_pageDescription;

Print_r

SimpleXMLElement Object ( [settings] => SimpleXMLElement Object ( [ss_pageRef] => SimpleXMLElement Object ( ) [ss_pageType] => SimpleXMLElement Object ( ) [ss_navName] => SimpleXMLElement Object ( ) [ss_navWeight] => SimpleXMLElement Object ( ) [ss_navShow] => SimpleXMLElement Object ( ) [ss_indexShow] => SimpleXMLElement Object ( ) [ss_parentPage] => SimpleXMLElement Object ( ) [ss_pageTitle] => SimpleXMLElement Object ( ) [ss_pageDescription] => SimpleXMLElement Object ( ) [ss_pageBody] => SimpleXMLElement Object ( ) [galleryTitle] => SimpleXMLElement Object ( ) ) )

1 Answer 1

1

The reason it is not echo'ing anything is because <ss_PageDescription /> is nested within <settings />.

echo $galleries->settings->ss_pageDescription;
Sign up to request clarification or add additional context in comments.

Comments

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.