这个XML数据会在浏览器中解析吗?

时间:2014-08-18 10:44:30

标签: ajax

我在将XML数据解析到浏览器时遇到问题。有人可以告诉我这是否正常:

<?xml version="1.0"?>
<nutrition><daily-values><total-fat units="g">65</total-fat><saturated-fat units="g">20</saturated-fat><cholesterol units="mg">300</cholesterol><sodium units="mg">2400</sodium><carb units="g">300</carb><fiber units="g">25</fiber><protein units="g">50</protein></daily-values><food><name>Cole Slaw</name><mfr>Fresh Quick</mfr><serving units=" cup">1.5</serving><calories total="20" fat="0"/><total-fat>0</total-fat><saturated-fat>0</saturated-fat><cholesterol>0</cholesterol><sodium>15</sodium><carb>5</carb><fiber>2</fiber><protein>1</protein><vitamins><a>30</a><c>45</c></vitamins><minerals><ca>4</ca><fe>2</fe></minerals></food><food><name>Eggs</name><mfr>Goodpath</mfr><serving units="g">50</serving><calories total="70" fat="40"/><total-fat>4.5</total-fat><saturated-fat>1.5</saturated-fat><cholesterol>215</cholesterol><sodium>65</sodium><carb>1</carb><fiber>0</fiber><protein>6</protein><vitamins><a>6</a><c>0</c></vitamins><minerals><ca>2</ca><fe>4</fe></minerals></food><food><name>Hazelnut Spread</name><mfr>Ferreira</mfr><serving units="tbsp">2</serving><calories total="200" fat="90"/><total-fat>10</total-fat><saturated-fat>2</saturated-fat><cholesterol>0</cholesterol><sodium>20</sodium><carb>23</carb><fiber>2</fiber><protein>3</protein><vitamins><a>0</a><c>0</c></vitamins><minerals><ca>6</ca><fe>4</fe></minerals</food><food><name>Potato Chips</name><mfr>Lees</mfr><serving units="g">28</serving><calories total="150" fat="90"/><total-fat>10</total-fat><saturated-fat>3</saturated-fat><cholesterol>0</cholesterol><sodium>180</sodium><carb>15</carb><fiber>1</fiber><protein>2</protein><vitamins><a>0</a><c>10</c></vitamins><minerals><ca>0</ca><fe>0</fe></minerals></food><food><name>Soy Patties, Grilled</name><mfr>Gardenproducts</mfr><serving units="g">96</serving><calories total="160" fat="45"/><total-fat>5</total-fat><saturated-fat>0</saturated-fat><cholesterol>0</cholesterol><sodium>420</sodium><carb>10</carb><fiber>4</fiber><protein>9</protein><vitamins><a>0</a><c>0</c></vitamins><minerals><ca>0</ca><fe>0</fe></minerals></food><food><name>Truffles, Dark Chocolate</name><mfr>Lyndon's</mfr><serving units="g">39</serving><calories total="220" fat="170"/><total-fat>19</total-fat><saturated-fat>14</saturated-fat><cholesterol>25</cholesterol><sodium>10</sodium><carb>16</carb><fiber>1</fiber><protein>1</protein><vitamins><a>0</a><c>0</c></vitamins><minerals><ca>0</ca><fe>0</fe></minerals></food></nutrition>

3 个答案:

答案 0 :(得分:0)

名称为<name>Hazelnut Spread</name>的食物元素中缺少> 这里:

<fe>4</fe></minerals</food>

应该是:

<fe>4</fe></minerals></food>

答案 1 :(得分:0)

如果您复制此代码并将其保存到xml并在浏览器中打开,您会看到,在一个地方有</minerals</food>(输入错误的标记)

答案 2 :(得分:0)

此标记未关闭“<fe>4</fe></minerals” 使用以下代码进行更改

    <?xml version="1.0"?>
<nutrition>
    <daily-values>
        <total-fat units="g">65</total-fat>
        <saturated-fat units="g">20</saturated-fat>
        <cholesterol units="mg">300</cholesterol>
        <sodium units="mg">2400</sodium>
        <carb units="g">300</carb>
        <fiber units="g">25</fiber>
        <protein units="g">50</protein>
    </daily-values>
        <food>
            <name>Cole Slaw</name>
            <mfr>Fresh Quick</mfr>
            <serving units=" cup">1.5</serving>
            <calories total="20" fat="0"/>
            <total-fat>0</total-fat>
            <saturated-fat>0</saturated-fat>
            <cholesterol>0</cholesterol>
            <sodium>15</sodium>
            <carb>5</carb>
            <fiber>2</fiber>
            <protein>1</protein>
            <vitamins>
                <a>30</a>
                <c>45</c>
            </vitamins>
            <minerals>
                <ca>4</ca>
                <fe>2</fe>
            </minerals>
        </food>
        <food>
            <name>Eggs</name>
            <mfr>Goodpath</mfr>
            <serving units="g">50</serving>
            <calories total="70" fat="40"/>
            <total-fat>4.5</total-fat>
            <saturated-fat>1.5</saturated-fat>
            <cholesterol>215</cholesterol>
            <sodium>65</sodium>
            <carb>1</carb>
            <fiber>0</fiber>
            <protein>6</protein>
            <vitamins>
                <a>6</a>
                <c>0</c>
            </vitamins>
            <minerals>
                <ca>2</ca>
                <fe>4</fe>
            </minerals>
        </food>
        <food>
            <name>Hazelnut Spread</name>
            <mfr>Ferreira</mfr>
            <serving units="tbsp">2</serving>
            <calories total="200" fat="90"/>
            <total-fat>10</total-fat>
            <saturated-fat>2</saturated-fat>
            <cholesterol>0</cholesterol>
            <sodium>20</sodium>
            <carb>23</carb>
            <fiber>2</fiber>
            <protein>3</protein>
            <vitamins>
                <a>0</a>
                <c>0</c>
            </vitamins>
            <minerals>
                <ca>6</ca>
                <fe>4</fe>
            </minerals>

        </food>
        <food>
            <name>Potato Chips</name>
            <mfr>Lees</mfr>
            <serving units="g">28</serving>
            <calories total="150" fat="90"/>
            <total-fat>10</total-fat>
            <saturated-fat>3</saturated-fat>
            <cholesterol>0</cholesterol>
            <sodium>180</sodium>
            <carb>15</carb>
            <fiber>1</fiber>
            <protein>2</protein>
            <vitamins>
                <a>0</a>
                <c>10</c>
            </vitamins>
            <minerals>
                <ca>0</ca>
                <fe>0</fe>
            </minerals>
        </food>
        <food>
            <name>Soy Patties, Grilled</name>
            <mfr>Gardenproducts</mfr>
            <serving units="g">96</serving>
            <calories total="160" fat="45"/>
            <total-fat>5</total-fat>
            <saturated-fat>0</saturated-fat>
            <cholesterol>0</cholesterol>
            <sodium>420</sodium>
            <carb>10</carb>
            <fiber>4</fiber>
            <protein>9</protein>
            <vitamins>
                <a>0</a>
                <c>0</c>
            </vitamins>
            <minerals>
                <ca>0</ca>
                <fe>0</fe>
            </minerals>
        </food>
        <food>
            <name>Truffles, Dark Chocolate</name>
            <mfr>Lyndon's</mfr>
            <serving units="g">39</serving>
            <calories total="220" fat="170"/>
            <total-fat>19</total-fat>
            <saturated-fat>14</saturated-fat>
            <cholesterol>25</cholesterol>
            <sodium>10</sodium>
            <carb>16</carb>
            <fiber>1</fiber>
            <protein>1</protein>
            <vitamins>
                <a>0</a>
                <c>0</c>
            </vitamins>
            <minerals>
                <ca>0</ca>
                <fe>0</fe>
            </minerals>
        </food>

</nutrition>