Click to See Complete Forum and Search --> : xml file with attributes


meryls
04-15-2007, 09:09 AM
I am receiving this data in an xml file and have no idea how to parse and extract the data in a meaningful way. Every example I've seen in xml books and on xml websites uses elements and not attributes. Here is an example of this data:

<service_order_report>

<service_order project_name="ABC" service_order_number="33" author="bobw" report_to_group="dev" report_to_individual="leos" date_opened="2007-04-13 12:37:38.972" date_resolved="Unresolved" reported_by="bobw" reported_version="ABC2007" resolved_version="ABC007" resolved="false" due_date="2007-04-30" customer="N/A" total_cost="$0.00">

<attribute label="Company, Contact, Email, Phone">
Mispelled word in instructions on login page
</attribute>
<attribute label="Priority">Low</attribute>
<attribute label="Severity">Low</attribute>
<attribute label="Software Release">ABC2007</attribute>
<attribute label="Category">Customer-Low</attribute>
<attribute label="Build Type">Monthly</attribute>
<attribute label="Module">GUI</attribute>
<attribute label="Status">Assigned</attribute>
</service_order>

The originators of this xml provided a dtd:

<?xml version="1.0" encoding="UTF-8" ?>

<!ELEMENT service_order ( attribute*,
description*,
comment*,
resolution*,
attachment*,
billing*) >

<!ATTLIST service_order project_name CDATA #REQUIRED
service_order_number CDATA #REQUIRED
author CDATA #REQUIRED
report_to_group CDATA #REQUIRED
report_to_individual CDATA #REQUIRED
date_opened CDATA #REQUIRED
date_resolved CDATA #REQUIRED
reported_by CDATA #REQUIRED
reported_version CDATA #REQUIRED
resolved_version CDATA #REQUIRED
resolved ( true | false ) #REQUIRED
due_date CDATA #REQUIRED
customer CDATA #REQUIRED
total_cost CDATA #REQUIRED >

<!ELEMENT attribute ( #PCDATA ) >
<!ATTLIST attribute label CDATA #REQUIRED >

<!ELEMENT description EMPTY >
<!ATTLIST description entry CDATA #REQUIRED
date CDATA #REQUIRED
author CDATA #REQUIRED
text CDATA #REQUIRED >

<!ELEMENT comment EMPTY >
<!ATTLIST comment entry CDATA #REQUIRED
date CDATA #REQUIRED
author CDATA #REQUIRED
text CDATA #REQUIRED >

<!ELEMENT resolution EMPTY >
<!ATTLIST resolution entry CDATA #REQUIRED
date CDATA #REQUIRED
author CDATA #REQUIRED
text CDATA #REQUIRED >

<!ELEMENT attachment EMPTY >
<!ATTLIST attachment entry CDATA #REQUIRED
date CDATA #REQUIRED
author CDATA #REQUIRED
attachment_content_type CDATA #REQUIRED
attachment_file_name CDATA #REQUIRED
attachment_source_url CDATA #REQUIRED
attachment_description CDATA #IMPLIED >

<!ELEMENT billing EMPTY >
<!ATTLIST billing entry CDATA #REQUIRED
date CDATA #REQUIRED
type CDATA #REQUIRED
quantity CDATA #REQUIRED
rate CDATA #REQUIRED
cost CDATA #REQUIRED
user CDATA #REQUIRED
author CDATA #REQUIRED
description CDATA #IMPLIED )


<!ELEMENT service_order_report ( service_order* ) >

I'd like to present the data in an easy-to-read format using an html file.

Any help is appreciated.

( a small example would be great!)
Thanks!
Meryl

Charles
04-15-2007, 01:04 PM
I can think of several ways. What have you been using, XSLT?

meryls
04-15-2007, 03:27 PM
Just learning this in order to parse the xml file. I like the idea of a data island (http://www.w3schools.com/xml/xml_data_island.asp) since it is very simple, but with a good example I could adapt xslt. Thanks!

Kor
04-16-2007, 01:07 AM
Just learning this in order to parse the xml file. I like the idea of a data island (http://www.w3schools.com/xml/xml_data_island.asp) since it is very simple, but with a good example I could adapt xslt. Thanks!
The problem with that example is that is an IE only example... The same tutorial provides crossbrowser example of parsing the XML files:
http://www.w3schools.com/xml/xml_parser.asp

More details about the Mozilla's way:
http://developer.mozilla.org/en/docs/Parsing_and_serializing_XML

meryls
04-16-2007, 07:59 AM
Yes -- I saw that example, but there is no example that shows how to parse an xml with attributes as in the sample I attached to my original post. I have found no example anywhere to help me know how to extract and print the project name in <service_order project_name="ABC" ...> or the Priority in <attribute label="Priority">Low</attribute>.
Thanks for your interest. I appreciate the help.
Meryl