Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> plik xml wyciągnięcie odpowiednich informacji
skine
post
Post #1





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 26.05.2014

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


Witam, mam takie zadanie aby z pliku xml wyciągnąć odpowiednio id produktu oraz jego nazwę niemiecką(czyli 1 i 4 linia), a następnie zapisać to w pliku.
Za bardzo nie wiem jak się za to wziąć, może ktoś coś doradzi ? Z xml jeszcze nie miałem do czynienia także prosiłbym o jakieś najprostsze rozwiązania.
Tutaj fragment kodu





Kod
<product product_id = "15409">
            <name><![CDATA[EMAMODA SUKIENKA - CZARNY - BIAŁY 5705-8]]></name>
            <name_en><![CDATA[EMAMODA DRESS - BLACK - WHITE 5705-8]]></name_en>
            <name_de><![CDATA[EMAMODA DRESS - SCHWARZ - WEISS 5705-8]]></name_de>
                        <name_ru><![CDATA[EMAMODA ПЛАТЬЕ - черный - белый 5705-8]]></name_ru>
            <description><![CDATA[Szyfonowa sukienka z koronką<br /><p>
    <img alt=""" /></p><br /><iframe width="400" frameborder="no" src=""></iframe>]]></description>
            <description_en><![CDATA[Chiffon dress with lace<br /><p>
    <img alt="" src="" /></p><br /><iframe width="400" frameborder="no" src=""></iframe>]]></description_en>
            <description_de><![CDATA[Chiffon-Kleid mit Spitze<br /><p>
    <img alt="" src="" /></p><br /><iframe width="400" frameborder="no" src=""></iframe>]]></description_de>
                        <description_ru><![CDATA[Шифон платье с кружевом<br /><p>
    <img alt="" src="" /></p><br /><iframe width="400" frameborder="no" src=""></iframe>]]></description_ru>
            <code>5705-8</code>
            <producer_code>Y593</producer_code>
            <type>f</type>
            <producer><![CDATA[Emamoda]]></producer>
            <photos>
                            <photo></photo>
                <photo></photo>
                
                <photo></photo>
                
                <photo></photo>
                
            </photos>
            <category_id>15</category_id>
            <category_id2>0</category_id2>
            <add_date>2014-05-05 08:39:42</add_date>
            <price_netto>61.40</price_netto>
            <sale>0</sale>
            <sale_price_netto>0.00</sale_price_netto>
            <fillup>0</fillup>
            <sizes>
                <size name="S" count="1" />
                <size name="M" count="4" />
                <size name="L" count="3" />
            </sizes>
                        <color><![CDATA[CZARNY - BIAŁY]]></color>
                        <color_en><![CDATA[BLACK - WHITE]]></color_en>
            <color_de><![CDATA[SCHWARZ - WEISS]]></color_de>
                        <color_ru><![CDATA[BLACK - WHITE]]></color_ru>
                        <cloth><![CDATA[100% poliester]]></cloth>
                        <cloth_en><![CDATA[100% poliester]]></cloth_en>
            <cloth_de><![CDATA[100% poliester]]></cloth_de>
                        <cloth_ru><![CDATA[100% poliester]]></cloth_ru>
                        <price_netto_eur>15.24</price_netto_eur>


Ten post edytował skine 26.05.2014, 17:06:45
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Turson
post
Post #2





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Jak już masz otwarty plik xml np. w $plik i chcesz się dostać do product_id to
  1. echo $plik->product['product_id'];
Go to the top of the page
+Quote Post
skine
post
Post #3





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 26.05.2014

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


Cytat(Turson @ 27.05.2014, 12:34:36 ) *
Jak już masz otwarty plik xml np. w $plik i chcesz się dostać do product_id to
  1. echo $plik->product['product_id'];


Tak wygląda od początku xml


Kod
<?xml version="1.0" encoding="utf-8"?>
<root targetNamespace="http://yournewstyle.pl">
    <date>2014-05-26 03:02:30</date>
    <categories>
        <category category_id = "1">
            <parent>0</parent>
            <name><![CDATA[Damskie]]></name>
        </category>
        <category category_id = "2">
            <parent>0</parent>
            <name><![CDATA[Męskie]]></name>
        </category>
        <category category_id = "3">
            <parent>0</parent>
            <name><![CDATA[Dodatki]]></name>
        </category>
        <category category_id = "33">
            <parent>2</parent>
            <name><![CDATA[Koszule]]></name>
        </category>
        <category category_id = "12">
            <parent>1</parent>
            <name><![CDATA[Kurtki i Płaszcze]]></name>
        </category>
        <category category_id = "34">
            <parent>2</parent>
            <name><![CDATA[Bluzki]]></name>
        </category>
        <category category_id = "13">
            <parent>1</parent>
            <name><![CDATA[Spodnie i spodenki]]></name>
        </category>
        <category category_id = "51">
            <parent>2</parent>
            <name><![CDATA[Długi rękaw]]></name>
        </category>
        <category category_id = "15">
            <parent>1</parent>
            <name><![CDATA[Sukienki ]]></name>
        </category>
        <category category_id = "52">
            <parent>2</parent>
            <name><![CDATA[Spodnie, spodenki]]></name>
        </category>
        <category category_id = "16">
            <parent>1</parent>
            <name><![CDATA[Swetry]]></name>
        </category>
        <category category_id = "55">
            <parent>2</parent>
            <name><![CDATA[Swetry]]></name>
        </category>
        <category category_id = "17">
            <parent>1</parent>
            <name><![CDATA[Topy]]></name>
        </category>
        <category category_id = "50">
            <parent>3</parent>
            <name><![CDATA[Szale]]></name>
        </category>
        <category category_id = "18">
            <parent>1</parent>
            <name><![CDATA[Tuniki]]></name>
        </category>
        <category category_id = "19">
            <parent>1</parent>
            <name><![CDATA[Obuwie]]></name>
        </category>
        <category category_id = "20">
            <parent>1</parent>
            <name><![CDATA[Komplety]]></name>
        </category>
        <category category_id = "23">
            <parent>1</parent>
            <name><![CDATA[Spódniczki]]></name>
        </category>
        <category category_id = "24">
            <parent>1</parent>
            <name><![CDATA[Koszule]]></name>
        </category>
        <category category_id = "27">
            <parent>1</parent>
            <name><![CDATA[Bluzki]]></name>
        </category>
        <category category_id = "28">
            <parent>1</parent>
            <name><![CDATA[Dodatki]]></name>
        </category>
        <category category_id = "30">
            <parent>1</parent>
            <name><![CDATA[Stroje kąpielowe]]></name>
        </category>
        <category category_id = "35">
            <parent>1</parent>
            <name><![CDATA[Marynarki i żakiety]]></name>
        </category>
    </categories>
    <products>
        <product product_id = "15409">
            <name><![CDATA[EMAMODA SUKIENKA - CZARNY - BIAŁY 5705-8]]></name>
            <name_en><![CDATA[EMAMODA DRESS - BLACK - WHITE 5705-8]]></name_en>
            <name_de><![CDATA[EMAMODA DRESS - SCHWARZ - WEISS 5705-8]]></name_de>
                        <name_ru><![CDATA[EMAMODA ПЛАТЬЕ - черный - белый 5705-8]]></name_ru>
            <description><![CDATA[Szyfonowa sukienka z koronką<br /><p>
    <img alt="" src="http://www.yournewstyle.pl/grafika/wymiary/emamoda2.gif" /></p><br /><iframe width="400" frameborder="no" src="http://www.youtube.com/embed/yH4UPXFsu-Y?rel=1&amp;autoplay=1"></iframe>]]></description>
            <description_en><![CDATA[Chiffon dress with lace<br /><p>
    <img alt="" src="http://www.yournewstyle.pl/grafika/wymiary/emamoda2.gif" /></p><br /><iframe width="400" frameborder="no" src="http://www.youtube.com/embed/yH4UPXFsu-Y?rel=1&amp;autoplay=1"></iframe>]]></description_en>
            <description_de><![CDATA[Chiffon-Kleid mit Spitze<br /><p>
    <img alt="" src="http://www.yournewstyle.pl/grafika/wymiary/emamoda2.gif" /></p><br /><iframe width="400" frameborder="no" src="http://www.youtube.com/embed/yH4UPXFsu-Y?rel=1&amp;autoplay=1"></iframe>]]></description_de>
                        <description_ru><![CDATA[Шифон платье с кружевом<br /><p>
    <img alt="" src="http://www.yournewstyle.pl/grafika/wymiary/emamoda2.gif" /></p><br /><iframe width="400" frameborder="no" src="http://www.youtube.com/embed/yH4UPXFsu-Y?rel=1&amp;autoplay=1"></iframe>]]></description_ru>
            <code>5705-8</code>
            <producer_code>Y593</producer_code>
            <type>f</type>
            <producer><![CDATA[Emamoda]]></producer>
            <photos>
                            <photo>http://yournewstyle.pl/files/clothes/big/b93c898bbb07f29b19eca41ea7e0fbf1.jpg</photo>
                <photo>http://yournewstyle.pl/files/clothes/big/cf77f3e0c0595f243e52cb1838c5769f.jpg</photo>
                
                <photo>http://yournewstyle.pl/files/clothes/big/64c2c591dc85e668f64dd5a34cf1d6ab.jpg</photo>
                
                <photo>http://yournewstyle.pl/files/clothes/big/d3e5a098e1e3fcc2e2cf2c3f5bb02c2c.jpg</photo>
                
            </photos>
            <category_id>15</category_id>
            <category_id2>0</category_id2>
            <add_date>2014-05-05 08:39:42</add_date>
            <price_netto>61.40</price_netto>
            <sale>0</sale>
            <sale_price_netto>0.00</sale_price_netto>
            <fillup>0</fillup>
            <sizes>
                <size name="S" count="1" />
                <size name="M" count="4" />
                <size name="L" count="3" />
            </sizes>
                        <color><![CDATA[CZARNY - BIAŁY]]></color>
                        <color_en><![CDATA[BLACK - WHITE]]></color_en>
            <color_de><![CDATA[SCHWARZ - WEISS]]></color_de>
                        <color_ru><![CDATA[BLACK - WHITE]]></color_ru>
                        <cloth><![CDATA[100% poliester]]></cloth>
                        <cloth_en><![CDATA[100% poliester]]></cloth_en>
            <cloth_de><![CDATA[100% poliester]]></cloth_de>
                        <cloth_ru><![CDATA[100% poliester]]></cloth_ru>
                        <price_netto_eur>15.24</price_netto_eur>
                        

        </product>


Kod
<?php

$xml = simplexml_load_file("yournewstyle.xml");

echo $xml->products->product['product_id'];

?>

To tak powinno wyglądać ?

Ten post edytował skine 27.05.2014, 11:55:45
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 19.11.2025 - 12:01