ช่วยหน่อยครับเรื่อง XML Stlysheet

HTML Basic
สำหรับนักพัฒนาเว็บไซต์มือใหม่ HTML , CSS และการใช้ Tools ต่างๆ ในการพัฒนาเว็บไซต์

Moderator: mindphp

Onear
PHP Newbie
PHP Newbie
โพสต์: 1
ลงทะเบียนเมื่อ: 03/09/2012 11:17 pm

ช่วยหน่อยครับเรื่อง XML Stlysheet

โพสต์ที่ยังไม่ได้อ่าน โดย Onear »

นี่เป็นส่วนของ XML จะเขียน css กำหนดยังไงให้แสดงเป็นแบบในรูปอ่ะครับ
<?xml version="1.0" encoding="UTF-8"?>
<collection>
<description>
Some recipes used in the XML tutorial.
</description>
<recipe>
<title>Beef Parmesan with Garlic Angel Hair Pasta</title>
<ingredient name="beef cube steak" amount="1.5" unit="pound"/>
<ingredient name="onion, sliced into thin rings" amount="1"/>
<ingredient name="green bell pepper, sliced in rings" amount="1"/>
<ingredient name="Italian seasoned bread crumbs" amount="1" unit="cup"/>
<ingredient name="grated Parmesan cheese" amount="0.5" unit="cup"/>
<ingredient name="olive oil" amount="2" unit="tablespoon"/>
<ingredient name="spaghetti sauce" amount="1" unit="jar"/>
<ingredient name="shredded mozzarella cheese" amount="0.5" unit="cup"/>
<ingredient name="angel hair pasta" amount="12" unit="ounce"/>
<ingredient name="minced garlic" amount="2" unit="teaspoon"/>
<ingredient name="butter" amount="0.25" unit="cup"/>
<preparation>
<step>
Preheat oven to 350 degrees F (175 degrees C).
</step>
<step>
Cut cube steak into serving size pieces. Coat meat with the bread crumbs
and parmesan cheese. Heat olive oil in a large frying pan, and saute 1
teaspoon of the garlic for 3 minutes. Quick fry (brown quickly on both sides)
meat. Place meat in a casserole baking dish, slightly overlapping edges.
Place onion rings and peppers on top of meat, and pour marinara sauce
over all.
</step>
<step>
Bake at 350 degrees F (175 degrees C) for 30 to 45 minutes, depending on
the thickness of the meat. Sprinkle mozzarella over meat and leave in the
oven till bubbly.
</step>
<step>
Boil pasta al dente. Drain, and toss in butter and 1 teaspoon garlic. For a
stronger garlic taste, season with garlic powder. Top with grated parmesan
and parsley for color. Serve meat and sauce atop a mound of pasta!
</step>
</preparation>
<comment>
Make the meat ahead of time, and refrigerate over night, the acid in the
tomato sauce will tenderize the meat even more. If you do this, save the
mozzarella till the last minute.
</comment>
<nutrition calories="1167" fat="23" carbohydrates="45" protein="32"/>
</recipe>
</collection>
แนบไฟล์
cats.jpg
cats.jpg (56.56 KiB) Viewed 4205 times
dreamlover
PHP Newbie
PHP Newbie
โพสต์: 1
ลงทะเบียนเมื่อ: 31/08/2012 10:10 am

Re: ช่วยหน่อยครับเรื่อง XML Stlysheet

โพสต์ที่ยังไม่ได้อ่าน โดย dreamlover »

ต้องใช้ XSLT จึงจะกรองข้อมูลออกมาได้อย่างที่ต้องการ, CSS จะช่วยแค่ปรับ layout เท่านั้น
ผมทำไฟล์คำตอบไว้ให้ ลองดาวโหลดมาดูได้ที่
http://www.mineinc.net/qa/file.xml
ผมพยายามเขียนไว้ในกระทู้นี้แล้ว แต่ดูแล้วเข้าใจยากมาก ไม่รู้เหมือนกันว่าลิงค์แบบนี้ผิดกฏหรือเปล่า
อาจจะตอบช้าไปหน่อย เพิ่งเข้ามาเป็นสมาชิกที่นี่ หวังว่าคงช่วยได้บ้างนะครับ
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41125
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: ช่วยหน่อยครับเรื่อง XML Stlysheet

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

ไฟล์ xml ผิดรูปแบบ
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
tohkai_php
PHP Sr. Member
PHP Sr. Member
โพสต์: 95
ลงทะเบียนเมื่อ: 10/04/2012 9:09 am

Re: ช่วยหน่อยครับเรื่อง XML Stlysheet

โพสต์ที่ยังไม่ได้อ่าน โดย tohkai_php »

ต้องอ่าน xml ก่อนอะ เสร็จแล้วเอาแต่ละ row มาใส่ css กำหนด

ตัวอย่างโหลด xml

โค้ด: เลือกทั้งหมด

<?php
function objectsIntoArray($arrObjData, $arrSkipIndices = array())
{
    $arrData = array();
   
    // if input is object, convert into array
    if (is_object($arrObjData)) {
        $arrObjData = get_object_vars($arrObjData);
    }
   
    if (is_array($arrObjData)) {
        foreach ($arrObjData as $index => $value) {
            if (is_object($value) || is_array($value)) {
                $value = objectsIntoArray($value, $arrSkipIndices); // recursive call
            }
            if (in_array($index, $arrSkipIndices)) {
                continue;
            }
            $arrData[$index] = $value;
        }
    }
    return $arrData;
}
?>

Usage:

<?php
$xmlUrl = "feed.xml"; // XML feed file/URL
$xmlStr = file_get_contents($xmlUrl);
$xmlObj = simplexml_load_string($xmlStr);
$arrXml = objectsIntoArray($xmlObj);
print_r($arrXml);
?>
พอได้ array มาก็เอาไปใส่ตาม design ใน html ได้เลยอะครับ
ตอบกลับโพส

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 43