Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [XML][PHP] Nie wyświetla struktury pliku XML
-gosc-
post 26.10.2012, 08:25:40
Post #1





Goście







Witam,

chciałbym wyświetlić a następnie wyedytować lementy z PatchEffect level="0" dla poszczególnych Spectrum value pliku XML.
Plik ma postać:

  1. <?xml version="1.0"?>
  2. <Path_Effect_Table version="1">
  3. <Path name="MOD1">
  4. <WhenDone>2012-10-25 13:01:49</WhenDone>
  5. <Spectrum value="8.35E+008">
  6. <PathEffect level="0">-11</PathEffect>
  7. </Spectrum>
  8. <Spectrum value="8.37E+008">
  9. <PathEffect level="0">-15</PathEffect>
  10. </Spectrum>
  11. <Spectrum value="8.8E+008">
  12. <PathEffect level="0">-10</PathEffect>
  13. </Spectrum>
  14. </Path>
  15. <Path name="MOD2">
  16. <WhenDone>2012-10-25 12:39:37</WhenDone>
  17. <Spectrum value="8.35E+008">
  18. <PathEffect level="0">-12</PathEffect>
  19. </Spectrum>
  20. <Spectrum value="8.37E+008">
  21. <PathEffect level="0">-17</PathEffect>
  22. </Spectrum>
  23. <Spectrum value="8.8E+008">
  24. <PathEffect level="0">-10</PathEffect>
  25. </Spectrum>
  26. </Path>
  27. </Path_Effect_Table>


Na początek wyświetlam w sposób jak poniżej i otrzymuję jedynie:

Path_Effect_Table
Path:
Path:


  1. $xml = simplexml_load_file("test.xml"); //wczytanie pliku xml
  2. echo $xml->getName() . "<br />";
  3.  
  4. foreach($xml->children() as $child)
  5. {
  6. echo $child->getName() . ": " . $child . "<br />";
  7. }
Go to the top of the page
+Quote Post
Tomplus
post 26.10.2012, 11:34:56
Post #2





Grupa: Zarejestrowani
Postów: 1 879
Pomógł: 230
Dołączył: 20.03.2005
Skąd: Będzin

Ostrzeżenie: (0%)
-----


  1. foreach($xml->Path_Effect_Table->Path as $child)
  2. {
  3. echo $child->getName() . ": " . $child . "<br />";
  4. }


mam nadzieję że błędu nie popełniłem.

Ten post edytował Tomplus 26.10.2012, 11:35:22
Go to the top of the page
+Quote Post
-Gość-
post 26.10.2012, 11:54:23
Post #3





Goście







Wynik:

Path_Effect_Table

Warning: Invalid argument supplied for foreach() in /var/www/dt/4/index.php on line 5

Za pomocą poniższego udało mi się wyświeltić dane z MOD1

  1. foreach ($xml->Path->Spectrum as $typ)
  2. {
  3. foreach ($typ->PathEffect as $wartosc) {
  4. echo $wartosc;
  5. }
  6. echo '<br><br>';
  7. }


Dostałem taki wynik, nie potrafie tylko pobrać danych z name=MOD2

-11
-15
-10
Go to the top of the page
+Quote Post
-Gość-
post 26.10.2012, 12:39:25
Post #4





Goście







Może inaczej.

Jeżeli zastosuję komendę

  1. $xml = simplexml_load_file("test.xml"); //wczytanie pliku xml
  2. foreach ($xml->Path as $typ)
  3. {
  4. echo '<pre>';
  5. print_r($typ);
  6. echo '</pre>';
  7. }


otrzymam taki wynik

Kod
SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [name] => MOD1
        )

    [WhenDone] => 2012-10-25 13:01:49
    [Spectrum] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [value] => 8.35E+008
                        )

                    [PathEffect] => -11
                )

            [1] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [value] => 8.37E+008
                        )

                    [PathEffect] => -15
                )

            [2] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [value] => 8.8E+008
                        )

                    [PathEffect] => -10
                )

        )

)

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [name] => MOD2
        )

    [WhenDone] => 2012-10-25 12:39:37
    [Spectrum] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [value] => 8.35E+008
                        )

                    [PathEffect] => -12
                )

            [1] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [value] => 8.37E+008
                        )

                    [PathEffect] => -17
                )

            [2] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [value] => 8.8E+008
                        )

                    [PathEffect] => -10
                )

        )

)


Próbuję teraz odwołać się do poszczególnych danych ale mam problem. Poniższe wyświetli MOD1 oraz MOD2. Jak teraz wyświetlić value i PathEffect

  1. foreach ($xml->Path as $typ)
  2. {
  3. echo $typ[name];
  4. }
Go to the top of the page
+Quote Post
Bart123
post 10.05.2014, 22:56:39
Post #5





Grupa: Zarejestrowani
Postów: 105
Pomógł: 0
Dołączył: 10.05.2014
Skąd: Elbląg

Ostrzeżenie: (10%)
X----


Chętnie się podłączę do tego tematu ponieważ dotyczy mojego problemu.

Wyświetliłem sobie już całą zawartość pliku settings.xml na stronie - oprócz wartości każdego elementu czyli Value

Jest np tak

Rodzic

Dziecko value=256

Pytanie brzmi - w jaki sposób wyświetlić na stronie to 256?
Go to the top of the page
+Quote Post
dje31
post 10.05.2014, 23:11:49
Post #6





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 17.03.2009
Skąd: Karpacz

Ostrzeżenie: (0%)
-----


Bart123 o to ci chodzi ?

  1.  
  2. $link = simplexml_load_file('http://twojadomena.pl?Type=xml') or die('blad');
  3. foreach ($link->rodzic->dziecko as $event3)
  4. {
  5. echo $event3['value'];
  6.  
  7.  
  8. }
  9.  
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 04:29