Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP][XML]Co i jak?
Victor152
post
Post #1





Grupa: Zarejestrowani
Postów: 105
Pomógł: 3
Dołączył: 26.02.2008

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


Witam mam taki dokument xml:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <bans>
  3. <ban type="2" player="SaMoLoN" time="-1" reason="nothing"/>
  4. <ban type="2" player="AaaaaA" time="-1" reason="nothing"/>

I chce w tabelce z niego odcczytać type, player, time i reason.
Proszę o wskazówki.
Go to the top of the page
+Quote Post
bełdzio
post
Post #2





Grupa: Zarejestrowani
Postów: 690
Pomógł: 81
Dołączył: 6.04.2005
Skąd: Szczecin

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


hmm najprosciej preg_match_all +

'@<ban type="(.*?)" player="(.*?)" time="(.*?)" reason="(.*?)"/>@si'
Go to the top of the page
+Quote Post
Victor152
post
Post #3





Grupa: Zarejestrowani
Postów: 105
Pomógł: 3
Dołączył: 26.02.2008

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


Wolałbym skorzystać z prawdziwych funkcji XMLA [domu].
Go to the top of the page
+Quote Post
nospor
post
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




to skoro chcesz uzyc dom, to uzyj dom:
http://pl2.php.net/manual/pl/book.dom.php
w czym problemm?

A jak chcesz tylko czytac to uzyj simpleXML
http://pl2.php.net/manual/pl/book.simplexml.php
jest prostrzy
Go to the top of the page
+Quote Post
Victor152
post
Post #5





Grupa: Zarejestrowani
Postów: 105
Pomógł: 3
Dołączył: 26.02.2008

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


simplexml mi na xampie nie śmiga
Jednak zmieniam zdanie i jakiś przykład z domem by się przydał.
Go to the top of the page
+Quote Post
nospor
post
Post #6





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




dostales linka, masz tam mase przykladow...

Uzyj np. xpath:
http://pl2.php.net/manual/pl/domxpath.query.php
Go to the top of the page
+Quote Post
Victor152
post
Post #7





Grupa: Zarejestrowani
Postów: 105
Pomógł: 3
Dołączył: 26.02.2008

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


To:
  1. <?php
  2. $domDocument = new DOMDocument;
  3. $domDocument->loadXML("bans.xml");
  4. $domXPath = new DOMXPath($domDocument);
  5. foreach ($domXPath->query('//ban') as $keyDOM) {
  6. echo $keyDOM->getAttribute('type');
  7. }
  8. ?>

Wyrzuca to:
Cytat
Warning: DOMDocument::loadXML() [domdocument.loadxml]: Start tag expected, '<' not found in Entity, line: 1 in C:\Program Files\xampp\htdocs\nikol\bans_xml.php on line 3

Any ideas?
Go to the top of the page
+Quote Post
nospor
post
Post #8





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




a <bans> zamykasz? Bo w xml co pokazales nie robisz tego
Go to the top of the page
+Quote Post
Victor152
post
Post #9





Grupa: Zarejestrowani
Postów: 105
Pomógł: 3
Dołączył: 26.02.2008

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


zamykam, </bans>

#Down
:*

Ten post edytował Victor152 14.08.2008, 13:17:30
Go to the top of the page
+Quote Post
nospor
post
Post #10





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




no dobra, ale patrz jakich funkcji uzywasz:
http://pl2.php.net/manual/pl/domdocument.loadxml.php
I co napisali ze ona robi?

Masz uzyc load()
  1. <?php
  2. $domDocument = new DOMDocument;
  3. $domDocument->load("bans.xml");
  4. $domXPath = new DOMXPath($domDocument);
  5. foreach ($domXPath->query('//ban') as $keyDOM) {
  6. echo $keyDOM->getAttribute('type');
  7. }
  8. ?>

Nawet w przykladzie co ci dawalem byli load(). Kopiowac tez trzeba umiec (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)
Go to the top of the page
+Quote Post

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: 22.08.2025 - 20:02