|
|
#1 (permalink) |
|
Üyelik Tarihi: 09.11.2006
Yer: izmir
Mesaj: 194
|
XML'den veri alma
Merhabalar arkadaşlar. PHP ile bir XML den veri almak istiyorum. XML içindeki kodlar şu şekilde :
HTML Code:
<?XML version="1.0" standalone="yes" ?> <report> <table> <columns> <column name="campaign" /> <column name="adgroup" /> <column name="keyword" /> <column name="currCode" /> <column name="imps" /> <column name="clicks" /> <column name="ctr" /> <column name="cpc" /> <column name="cpm" /> <column name="cost" /> <column name="pos" /> </columns> <rows> <row campaign="FiloHost" adgroup="hosting" keyword="Toplam - içerik hedefleme" currCode="TRY" imps="676470" clicks="623" ctr="9.209573225715848E-4" cpc="41589" cpm="38301" cost="25910000" pos="5.0534643074" /> <row campaign="FiloHost" adgroup="hosting" keyword="ASP destekli host" currCode="TRY" imps="47" clicks="1" ctr="0.02127659574468085" cpc="430000" cpm="9148936" cost="430000" pos="2.2553191489" /> <row campaign="FiloHost" adgroup="hosting" keyword="ASP destekli hosting" currCode="TRY" imps="19" clicks="0" ctr="0.0" cpc="0" cpm="0" cost="0" pos="4.3684210526" /> <row campaign="FiloHost" adgroup="hosting" keyword="ASP host" currCode="TRY" imps="150" clicks="0" ctr="0.0" cpc="0" cpm="0" cost="0" pos="4.1533333333" /> </rows> </table> </report> Şimdi ben bu verilerle şöyle bir tablo hazırlamak istiyorum. Şimdi columns tagları arasındaki değerlere göre kolonlar oluşturacam. kolonlar işte campaign, adgroup vb. olacak. daha sonra alttaki row satırlarındaki değerleride bu kolonlara yerleştirecem. row tagındaki campaign değerini ilk satırdaki campaign kolonuna, adgroupu adgroup kolonuna vs. Yardımcı olursanız çok sevinirim. İnternette hep tagların arasındaki değerleri alma var. Tagların içindeki diğer değişkenleri almayı bulamadım. |
|
|
|
|
|
#4 (permalink) |
|
Re: XML'den veri alma
Aşağıdaki örnek tam istediğinizi karşılayacaktır, PHP5 ve SimpleXML kütüphanesini gerektirir.
PHP Code:
__________________
meteryus.com // geri döndü |
|
|
|
|
|
|
#5 (permalink) |
|
Üyelik Tarihi: 09.11.2006
Yer: izmir
Mesaj: 194
|
Re: XML'den veri alma
Diğer herşey tamamda şu bölümü anlayamadım.
HTML Code:
$xmlstr = <<<XML <?XML version="1.0" standalone="yes" ?> <report> <table> <columns> <column name="campaign" /> <column name="adgroup" /> <column name="keyword" /> <column name="currCode" /> <column name="imps" /> <column name="clicks" /> <column name="ctr" /> <column name="cpc" /> <column name="cpm" /> <column name="cost" /> <column name="pos" /> </columns> <rows> <row campaign="FiloHost" adgroup="hosting" keyword="Toplam - içerik hedefleme" currCode="TRY" imps="676470" clicks="623" ctr="9.209573225715848E-4" cpc="41589" cpm="38301" cost="25910000" pos="5.0534643074" /> <row campaign="FiloHost" adgroup="hosting" keyword="ASP destekli host" currCode="TRY" imps="47" clicks="1" ctr="0.02127659574468085" cpc="430000" cpm="9148936" cost="430000" pos="2.2553191489" /> <row campaign="FiloHost" adgroup="hosting" keyword="ASP destekli hosting" currCode="TRY" imps="19" clicks="0" ctr="0.0" cpc="0" cpm="0" cost="0" pos="4.3684210526" /> <row campaign="FiloHost" adgroup="hosting" keyword="ASP host" currCode="TRY" imps="150" clicks="0" ctr="0.0" cpc="0" cpm="0" cost="0" pos="4.1533333333" /> </rows> </table> </report> XML; |
|
|
|
|
|
#6 (permalink) |
|
Re: XML'den veri alma
o bölümü include file_get_contents() ile değiştirebilirsin, ya da XML kodlarını PHP ile oluşturmak istersen include ile yüklersin. ,örnek çalışsın diye ben içine eklemiştim.
__________________
meteryus.com // geri döndü |
|
|
|
|
|
|
#9 (permalink) |
|
Re: XML'den veri alma
yukardaki örnek tam olarak istediğinizi yapıyor zaten, tagların içindeki verilere simpleXml sınıfının attributes() fonksiyonu ile ulaşıyorsun.
Ayrıca "beceremedim" net bir cevap değil hatanın ne olduğu yada ne gibi bir sorun yaşadığını yazarsan belki yardımcı olunabilir.
__________________
meteryus.com // geri döndü |
|
|
|
|
|
|
#10 (permalink) |
|
Üyelik Tarihi: 09.11.2006
Yer: izmir
Mesaj: 194
|
Re: XML'den veri alma
üstad şimdi verdiğin örneği şöyle yaptım
PHP Code:
HTML Code:
--------------------------------------------------------------------------------
Tablo : Row : Row 0 : Attributes
campaign="FiloHost"
adgroup="hosting"
keyword="Toplam - içerik hedefleme"
currCode="TRY"
imps="676470"
clicks="623"
ctr="9.209573225715848E-4"
cpc="41589"
cpm="38301"
cost="25910000"
pos="5.0534643074"
--------------------------------------------------------------------------------
Tablo : Columns : Column 0 : Attributes
name="campaign"
--------------------------------------------------------------------------------
Tablo : Columns : Column 0
SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => campaign
)
)
--------------------------------------------------------------------------------
Tablo : Columns
SimpleXMLElement Object
(
[column] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => campaign
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => adgroup
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => keyword
)
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => currCode
)
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => imps
)
)
[5] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => clicks
)
)
[6] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => ctr
)
)
[7] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => cpc
)
)
[8] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => cpm
)
)
[9] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => cost
)
)
[10] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => pos
)
)
)
)
|
|
|
|
Zoque'a hoşgeldiniz!