You are here:  » Preview Output


Preview Output

Submitted by markoja on Fri, 2008-08-15 21:17 in

Hi David,

Can you please help me about parsed data from xml.
My preview looks like this:

Array ( [IZDELEK] => [IZDELEK-ST] => 1 [IZDELEKID] => 1999788 [IZDELEKIME] => Kodak EX-811 Dig.Picture Frame [OPIS] =>
- podpora slikovnih formatov JPEG,EXIF,
- podpora video formatov MOV,AVI,MPEG1 in MPEG4,
- podpora audio formatov MP3,
- dimenzije 284 × 211 × 38 mm,
- vidna površina 176 × 100 mm (8"),
- ločljivost zaslona 800 × 480, 16:9 widescreen,
- 128MB internega spomina, podpora SD/MMC/
- MS/xD/CF/MD karticam, svetilnost 300 NITs,
- kontrast 300:1, podpora WiFi 802.11b/g
[SLIKAMALA] => http://box.si/articleimages/13/0020/0010/imgArticle_55.jpg [DC] => 119,5 [PPC] => 143,4 [DAVCNASTOPNJA] => 20 [KATEGORIJA] => DIGITALNI OKVIRJI [KATEGORIJA-ID] => 130020 [BLAGOVNAZNAMKA] => KODAK [BLAGOVNAZNAMKA-ID] => 13 [DOBAVA] => Ni na zalogi [DOBAVA-ID] => ni na zalogi [URL] => http://box.si/article.asp?ArticleID=55 [SLIKAVELIKA] => http://box.si/articleimages/13/0020/0010/imgBigArticle_1_55.jpg ) Array ( [IZDELEK] => [IZDELEK-ST] => 2 [IZDELEKID] => 8714941 [IZDELEKIME] => Kodak EX-1011 Dig.Picture Fram [OPIS] =>
- podpora slikovnih formatov JPEG,EXIF,
- podpora video formatov MOV,AVI,MPEG1 in MPEG4,
- podpora audio formatov MP3,
- dimenzije 330 × 241 × 41 mm,
- vidna površina 225 × 135 mm (10"),
- ločljivost zaslona 800 × 480, 16:9 widescreen,
- 128MB internega spomina, podpora SD/MMC/
- MS/xD/CF/MD karticam, svetilnost 350 NITs,
- kontrast 300:1, podpora WiFi 802.11b/g
[SLIKAMALA] => http://box.si/articleimages/13/0020/0010/imgArticle_58.jpg [DC] => 150 [PPC] => 180 [DAVCNASTOPNJA] => 20 [KATEGORIJA] => DIGITALNI OKVIRJI [KATEGORIJA-ID] => 130020 [BLAGOVNAZNAMKA] => KODAK [BLAGOVNAZNAMKA-ID] => 13 [DOBAVA] => Na zalogi [DOBAVA-ID] => na zalogi [URL] => http://box.si/article.asp?ArticleID=58 [SLIKAVELIKA] => http://box.si/articleimages/13/0020/0010/imgBigArticle_1_58.jpg )

Can you please send me code, how can I preview data like you have on demo page.
And I would like to preview only tagname and value, that's all.

Here is my code:

<?php
  
require("MagicParser.php");
  print 
"<table>";
  function 
myRecordHandler($record)
  {
        
// The following code will print out each field in your sample data:
    
print "<tr>";
    print 
"<th>Field</th>";
    print 
"<th>Content</th>";
    print 
"</tr>";
    print 
"<tr>";
    print 
"<th><nobr><b>IZDELEK</b></nobr></th></br>";
    print 
"<td>";
    print 
$record["IZDELEK"];
    print 
"</td>";
    print 
"</tr>";
    print 
"<tr>";
    print 
"<th><nobr>IZDELEK-ST</nobr></th>";
    print 
"<td>";
    print 
$record["IZDELEK-ST"];
    print 
"</td>";
    print 
"</tr>";
   }
?>

Kind Regards,
Marko

Submitted by support on Sat, 2008-08-16 08:33

Hello Marko,

Here's the basic idea:

<?php
  
function myRecordHandler($record)
  {
    print 
"<table>";
    print 
"<tr>";
    print 
"<th>Field</th>";
    print 
"<th>Content</th>";
    print 
"</tr>";
    foreach(
$record as $key => $value)
    {
      print 
"<tr>";
      print 
"<th>".$key."</th>"
      
print "<td>".$value."</td>";
      print 
"</tr>";
    }
    print 
"</table>";
    return 
TRUE;
  }
?>

The return TRUE; will mean that you only see the first record, which is probably what you want with a preview.

Hope this helps!
Cheers,
David.

Submitted by markoja on Sat, 2008-08-16 10:43

Hi David,

That's great, beacuse I need key and value data for inserting into database.
The only thing I need is that all products must be on one page. I must retreive all products.

Thanks, Marko

Submitted by support on Sat, 2008-08-16 10:56

Hi Marko,

No problem - just delete:

    return TRUE;

...from the end of the myRecordHandler() function and it will output a table for every record in the feed!

Cheers,
Davids.

Submitted by markoja on Sat, 2008-08-16 11:40

Hi David,

Sorry for asking so many questions!
I have another xml file, which has value CDATA[Nashuatec Barva za SPC410DN/411DN - cyan]]

The value is not showing in the table. Every tag that has a value like upper example is empty. On demo page the value is normally showed like this: [CDATA[Nashuatec Barva za SPC410DN/411DN - cyan]]

How to remove [CDATA[ code and only output "Nashuatec Barva za SPC410DN/411DN - cyan"

My code:

  function myRecordHandler($record)
  {
    print "<table border='1' style='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:10px;'>";
    print "<tr bgcolor='#cff3ae'>";
    print "<th>Field</th>";
    print "<th>Content</th>";
    print "</tr>";
    foreach($record as $key => $value)
    {
      print "<tr bgcolor='#e6e6e6'>";
      print "<th>".$key."</th>";
      print "<td>".$value."</td>";
      print "</tr>";
    }
    print "</table>";
    print "<br style='line-height:10px;' />";
  }

Thanks.

Marko

Submitted by support on Sat, 2008-08-16 11:46

Hello Marko,

It sounds as if the XML is incorrectly formatted, as CDATA sections are normally handled by the parser and the value in $record will only be the actual contents (not including the CDATA tags).

It may be that the way they are formatted is causing the data to be contained within <angle brackets> which means of course that it won't show up on a HTML page! They would however be visible if you did View > Source from your browser's menu.

To find out if this is the case, and probably good practice anyway; is to use htmlentities(). In your code, simply replace:

      print "<td>".$value."</td>";

...with:

      print "<td>".htmlentities($value)."</td>";

...and that should reveal what is going on.

Cheers!
David.

Submitted by markoja on Sat, 2008-08-16 12:01

Hi David,

Thanks. Now it's showing all data.
But I have now 2 problems:

1. Now the value is shown like this: ![CDATA[Apple pomnilnik 2GB 800Mhz DDR2 SODIMM]]
Is there a way, that I can replace this CDATA, that the value would bi only "Apple pomnilnik 2GB 800Mhz DDR2 SODIMM"

2. Problem with encoding.
Previous xml is showing normal, but this one like this:
![CDATA[ Apple pomnilniški modul je primeren za naslednje sisteme: - namizni ra�unalniki (iMac in Mac mini) - prenosniki (Macbook 13.3", Macbook Pro 15,4" in 17") S pove�anjem spomina, se pove�a skupna u�inkovitost sistema.]]

And I have at the top of the page:
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /

Characters I need are: š,č,ž

Really thanks for your help!

Kind Regards,
Marko

Submitted by markoja on Sat, 2008-08-16 12:26

Hi David,

I have already fixed both problems.
I'm really happy that I found Magic Parser on the web.

Kind Regards,
Marko

Submitted by markoja on Sun, 2008-08-17 16:21

Hi David,

I have one question about previewing my xml structure?
My xml looks like this:

<izdelki>
<izdelek st="1">
<izdelekID>1999788</izdelekID>
<izdelekIme>Kodak EX-811 Dig.Picture Frame</izdelekIme>
<opis>
<P> - podpora slikovnih formatov JPEG,EXIF,</P>
<P> - podpora video formatov MOV,AVI,MPEG1 in MPEG4,</P>
<P> - podpora audio formatov MP3,</P>
</opis>
<slikaMala>
http://b2b.alterna.si/articleimages/13/0020/0010/imgArticle_55.jpg
</slikaMala>
<DC>119,5</DC>
<PPC>143,4</PPC>
<davcnaStopnja>20</davcnaStopnja>
<kategorija id="130020">DIGITALNI OKVIRJI</kategorija>
<blagovnaZnamka id="13">KODAK</blagovnaZnamka>
<dobava id="ni na zalogi">Ni na zalogi</dobava>
<url>http://b2b.alterna.si/article.asp?ArticleID=55</url>
<slikaVelika>
http://b2b.alterna.si/articleimages/13/0020/0010/imgBigArticle_1_55.jpg
</slikaVelika>
</izdelek>

When I parse it:

FIELD | CONTENT
- podpora slikovnih formatov JPEG,EXIF,
OPIS - podpora video formatov MOV,AVI,MPEG1 in MPEG4,
- podpora audio formatov MP3,

I would that kind of the output:

FIELD | CONTENT
P@1 - podpora slikovnih formatov JPEG,EXIF,
P@2 - podpora video formatov MOV,AVI,MPEG1 in MPEG4,
P@3 - podpora audio formatov MP3,

I already did this, but I have to copy .xml file to my hard disk and remove tags <opis>. Is it possible, that Magic parser removes this tags <opis>.

I hope you understand my message.

Thanks, Marko

Submitted by support on Sun, 2008-08-17 16:54

Hello Marko,

I think a bit is missing from your post. Do you currently see:

OPIS/P
OPIS/P@1
OPIS/P@2

...as the field names?

This is the normal way that Magic Parser would resolve those duplicate fields, and can be handled quite easily within your code. Normally, you would not know how many P tags are in your XML, so the normal structure that I suggest looks something like this (within myRecordHandler):

    $i = 0;
    while(1) {
      if ($i) $postfix = "@".$i;
      if (!isset($record["OPIS/P".$prefix])) break;
      // use $record["OPIS/P".$prefix] here...
      $i++;
    }

Hope this helps,
Cheers,
David.

Submitted by markoja on Sun, 2008-08-17 17:40

Hello,

No I currently see only OPIS without P tags. That's very strange.

Just one OPIS and values (- podpora slikovnih formatov JPEG,EXIF, - podpora video formatov MOV,AVI,MPEG1 in MPEG4,).

But in xml there are <P> tags inside <OPIS> tag.

<izdelki>

<izdelek st="1">
<izdelekID>1999788</izdelekID>
<izdelekIme>Kodak EX-811 Dig.Picture Frame</izdelekIme>

<opis>
<P> - podpora slikovnih formatov JPEG,EXIF,</P><P> - podpora video formatov MOV,AVI,MPEG1 in MPEG4,</P><P> - podpora audio formatov MP3,</P><P> - dimenzije 284 × 211 × 38 mm,</P><P> - vidna površina 176 × 100 mm (8"),</P><P> - ločljivost zaslona 800 × 480, 16:9 widescreen,</P><P> - 128MB internega spomina, podpora SD/MMC/</P><P> - MS/xD/CF/MD karticam, svetilnost 300 NITs,</P><P> - kontrast 300:1, podpora WiFi 802.11b/g</P>
</opis>

<slikaMala>
http://b2b.alterna.si/articleimages/13/0020/0010/imgArticle_55.jpg
</slikaMala>
<DC>119,5</DC>
<PPC>143,4</PPC>
<davcnaStopnja>20</davcnaStopnja>
<kategorija id="130020">DIGITALNI OKVIRJI</kategorija>
<blagovnaZnamka id="13">KODAK</blagovnaZnamka>
<dobava id="ni na zalogi">Ni na zalogi</dobava>
<url>http://b2b.alterna.si/article.asp?ArticleID=55</url>

<slikaVelika>
http://b2b.alterna.si/articleimages/13/0020/0010/imgBigArticle_1_55.jpg
</slikaVelika>
</izdelek>

I tried like this $record["OPIS/P"] and I don't get anything.

Kind Regards,
Marko

Submitted by support on Sun, 2008-08-17 18:33

Hello Marko,

Are you sure that the content of the OPIS tag is not within CDATA brackets, which means that it isn't really part of the XML... It looks as if this section is intended to be HTML - and that they are paragraph tags...

If you do a View > Source, do you see the P tags; which would confirm this?

Cheers,
David.

Submitted by markoja on Sun, 2008-08-17 20:26

Hello David,

Content of the OPIS tag is not within CDATA brackets.
Yes you are right <P> is not the part of the XML, but <P> is paragraph.

Example, if the product has <P> - Model: AS5520-16Mi</P>, I would really like to have the output like
this:

<Model>AS5520-16Mi</Model>

I have already did this, but if I manually remove <opis> tag. Then I get the output
from Magic parser like this:
P - AS5520-16Mi
P@1 - xxxxxxxxxxx
P@2 - xxxxxxxxxxx

But I need to enter url into magic parser, I can't manually change xml file, beacuse the content of the xml is always changing.
Any suggestions?

Thank you for your help!

Kind Regards,
Marko

Submitted by support on Tue, 2008-08-19 08:57

Hello Marko,

I'm not sure why you're not seeing:

OPIS
OPIS/P - AS5520-16Mi
OPISP@1 - xxxxxxxxxxx
OPISP@2 - xxxxxxxxxxx

...which is what I would expect. Could you perhaps email me a copy of the actual XML (or the URL so that I can download it) and i'll check this out for you (you can use the email address on this page)...

Cheers,
David.