0

This is my XML file.

  <sekolah>
    <satuan_pendidikan>SMA/MA</satuan_pendidikan>
    <program-keahlian>-</program-keahlian>
    <program-tk />
    <nama-sekolah>SMA Bintang Kejora</nama-sekolah>
    <nss>10101623166</nss>
    <alamat>Jl Kemerdekaan</alamat>
    <kecamatan>Cengkareng</kecamatan>
    <kabupaten-kota>Jakarta</kabupaten-kota>
    <propinsi>Jakarta Barat</propinsi>
    <kodepos>12950</kodepos>
    <telepon>021-56246</telepon>
    <faksimili />
    <email>[email protected]</email>
    <status-sekolah>SWASTA</status-sekolah>
    <nama-yayasan>Bintang Kejora</nama-yayasan>
    <nomor-akte-pendirian-terakhir>92800</nomor-akte-pendirian-terakhir>
    <tahun-berdiri>2001</tahun-berdiri>
    <status-akreditasi />
    <visi>Visi</visi>
    <misi>Visi</misi>
  </sekolah>

This my PHP code.

$string = file_get_contents("sma-bintang-kejora.xml");
$xml = simplexml_load_string($string);
print_r ($xml) ;
echo '<hr />';

echo $xml->sekolah->satuan_pendidikan.'<br />';
echo $xml->sekolah->alamat.'<br />';
echo $xml->sekolah->kecamatan.'<br />';

I have an error when I try to echo $xml->sekolah->program-keahlian.'<br />'; // output will be 0.

Can we replace the index array on XML after the string "-"?

$xml = simplexml_load_string($string); 
1
  • What language are those tags in and what is a keahlian? Commented Apr 8, 2011 at 4:35

1 Answer 1

3

The dash in your tag means you have to use the {''} syntax:

echo (string)$xml->{'program-keahlian'};
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.