Advertisement

10.12.2003 at 10:21PM PDT, ID: 20764722
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

reading XML CDATA using W3C dom

Asked by petrolhead in Extensible Markup Language (XML), Extensible HTML (XHTML), Dynamic HTML (DHTML)

Tags: , , ,

Hi,

Does anyone know how to extract CDATA sections from an XML file using javascript and W3C dom? I cannot read the text that it stored between tags it keeps giving me an undefined object error.
For example:
my XML fie looks like

<vehicle_db>
      <vehicle ID="760KRT">
            <manufacturer>Honda</manufacturer>
            <model>Civic</model>
            <category>Sedan</category>
            <trim>EX-S</trim>
            <colour>Mettalic Blue</colour>
            <year>2003</year>
            <price>16600</price>
            <transmission>Automatic</transmission>
            <condition>New</condition>
            <odometer>0</odometer>
            <options>
                  <option>
                        <o_name>6 CD Changer</o_name>
                        <o_price>350</o_price>
                  </option>      
                  <option>
                        <o_name>Leather Seats</o_name>
                        <o_price>700</o_price>
                  </option>
                  <option>
                        <o_name>Fog Lights</o_name>
                        <o_price>200</o_price>
                  </option>
            </options>
            <picture>
                  <thumb>pictures/t_civic.jpg</thumb>
                  <full>pictures/f_civic.jpg</full>
            </picture>
      </vehicle>

      <vehicle ID="320FTN">
            <manufacturer>Honda</manufacturer>
            <model>Accord</model>
            <category>Sedan</category>
            <trim>LX</trim>
            <colour>Silver</colour>
            <year>1999</year>
            <price>17000</price>
            <transmission>Automatic</transmission>
            <condition>Used</condition>
            <odometer>17800</odometer>
            <picture>
                  <thumb>pictures/t_old_silver_accord.jpg</thumb>
                  <full>pictures/f_old_silver_accord.jpg</full>
            </picture>
      </vehicle>

Im trying to write a search function to search these fields. So lets say I wanted  the see the model for the first vehcile (want it to return Civic)? How would I do that?
My code right now is

<script type="text/javascript">
                  
                  function search()
                  {
                        topHandle = document.getElementsByTagName("vehicle_db");
                  
                        veh = topHandle.item(0);
                        
                        vehElements = veh.getElementsByTagName("vehicle");
                  
                        firstVe = vehElements.item(0);
                  
                        model = firstVe.getElementsByTagName("model");
                  
                                 //How to read the text (CDATA) within the model tags? (i.e. civic)
                        document.write(model1);

                        return;

}


I tried model.getValue but that didnt work.
model.text failed too, I cannot use the microsoft DOM, it has to be done using W3C with mozilla 1.4 as the reference browser.

ThanksStart Free Trial
[+][-]10.13.2003 at 12:37AM PDT, ID: 9538536

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Extensible Markup Language (XML), Extensible HTML (XHTML), Dynamic HTML (DHTML)
Tags: dom, javascript, reading, xml
Sign Up Now!
Solution Provided By: rdcpro
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32