473,225 Members | 1,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 software developers and data experts.

need help with parsing XML attributes

Hi-

I am using the following code and want to retrieve an attributes value.
I want to loop through the xml file and add the attribute values to an
array. The line in question is marked with "<---??????" below.

I have included both the PHP and XML.

Your help will be much appreciated.

Thanks.

PHP Source
################################################## #############
<?php
$headlines = array();
$urls = array();
$match = "";

function opening_element($parser, $element, $attributes) {
global $match;

if ($element == "HeadLine"){
$match = "headline";
}
elseif ($element == "NewsItemRef"){
$match = "url";
}
}
function closing_element($parser, $element) {

}
function character_data($parser, $data) {
global $match;
if ($match == "headline") {
global $headlines;
$headlines[] = $data;
}
elseif($match == "url") {
global $urls;
$urls[] = $data[1]; //<---??????
}
$match = "";
}

$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, true);
xml_set_element_handler($parser, "opening_element", "closing_element");
xml_set_character_data_handler($parser, "character_data");
$document = file("index.xml");
foreach ($document as $line) {
xml_parse($parser, $line);
}

foreach ($headlines as $name) {
echo "$name<br>\n";
}
foreach ($urls as $url) {
echo "$url<br>";
}
xml_parser_free($parser);

?>
XML Source
################################################## #############
<?xml version="1.0" encoding="iso-8859-1"?>
<NewsML>
<Catalog Href="http://www.afp.com/dtd/AFPCatalog.xml"/>
<NewsEnvelope>
<DateAndTime>20050409T055627Z</DateAndTime>
</NewsEnvelope>
<NewsItem>
<Identification>
<NewsIdentifier>
<ProviderId>afp.com</ProviderId>
<DateId>20050409</DateId>
<NewsItemId>ext--english--airlineweekly--airlines</NewsItemId>
<RevisionId PreviousRevision="0" Update="N">1</RevisionId>

<PublicIdentifier>urn:newsml:afp.com:20050409:ex t--english--airlineweekly--airlines:1</PublicIdentifier>
</NewsIdentifier>
<NameLabel></NameLabel>
</Identification>
<NewsManagement>
<NewsItemType FormalName="News"/>
<FirstCreated>20050409T055627Z</FirstCreated>
<ThisRevisionCreated>20050409T055627Z</ThisRevisionCreated>
<Status FormalName="Usable"/>
</NewsManagement>
<NewsComponent>
<AdministrativeMetadata>
<Provider>
<Party FormalName="AFP"/>
</Provider>
</AdministrativeMetadata>
<DescriptiveMetadata>
<Language FormalName="en"/>
</DescriptiveMetadata>
<NewsComponent>
<NewsLines>
<HeadLine>US aviation security chief resigns following
criticism</HeadLine>
</NewsLines>
<NewsItemRef NewsItem="050409055415.7x7vzi3y.xml"/>
</NewsComponent>
<NewsComponent>
<NewsLines>
<HeadLine>US regrets no deal with EU on Airbus-Boeing
handouts</HeadLine>
</NewsLines>
<NewsItemRef NewsItem="050408221056.h3y3hbvu.xml"/>
</NewsComponent>
<NewsComponent>
<NewsLines>
<HeadLine>Bush says his Christian faith reaffirmed at
pontiff's service</HeadLine>
</NewsLines>
<NewsItemRef NewsItem="050408142343.99d8pr2a.xml"/>
</NewsComponent>
<NewsComponent>
<NewsLines>
<HeadLine>More than 130 flights canceled in two days for
papal funeral</HeadLine>
</NewsLines>
<NewsItemRef NewsItem="050408140553.liphj5ts.xml"/>
</NewsComponent>
<NewsComponent>
<NewsLines>
<HeadLine>Gabon president determined to save troubled Air
Gabon</HeadLine>
</NewsLines>
<NewsItemRef NewsItem="050408101026.9ew2g9fc.xml"/>
</NewsComponent>
<NewsComponent>
<NewsLines>
<HeadLine>Korean Air plans regular flights to western China's
Xinjiang</HeadLine>
</NewsLines>
<NewsItemRef NewsItem="050408082516.r5qvpx32.xml"/>
</NewsComponent>
<NewsComponent>
<NewsLines>
<HeadLine>Parents of air stowaway sue airport, air company
for negligence</HeadLine>
</NewsLines>
<NewsItemRef NewsItem="050408062638.2uf11c8s.xml"/>
</NewsComponent>
<NewsComponent>
<NewsLines>
<HeadLine>Qantas hikes fuel surcharge after oil price
surge</HeadLine>
</NewsLines>
<NewsItemRef NewsItem="050408061511.uuemx1pw.xml"/>
</NewsComponent>
<NewsComponent>
<NewsLines>
<HeadLine>Former Garuda Indonesia top officials, pilot
questioned over activist death</HeadLine>
</NewsLines>
<NewsItemRef NewsItem="050408045039.qv2tzxpc.xml"/>
</NewsComponent>
<NewsComponent>
<NewsLines>
<HeadLine>Vietnam Airlines plans direct flights to
Germany</HeadLine>
</NewsLines>
<NewsItemRef NewsItem="050408044048.fg8ehp6v.xml"/>
</NewsComponent>
<NewsComponent>
<NewsLines>
<HeadLine>Camel costume prank sparks luggage handling probe
at Australia's Qantas</HeadLine>
</NewsLines>
<NewsItemRef NewsItem="050408043122.3c48ldbq.xml"/>
</NewsComponent>
<NewsComponent>
<NewsLines>
<HeadLine>Top EU competition official rails against
protection for big firms</HeadLine>
</NewsLines>
<NewsItemRef NewsItem="050407164004.3aikzi89.xml"/>
</NewsComponent>
<NewsComponent>
<NewsLines>
<HeadLine>Anti-aircraft missiles, marksmen: Rome smothered
under security blanket</HeadLine>
</NewsLines>
<NewsItemRef NewsItem="050407145944.2kxez8zg.xml"/>
</NewsComponent>
<NewsComponent>
<NewsLines>
<HeadLine>Dutch government reduces stake in Air
France-KLM</HeadLine>
</NewsLines>
<NewsItemRef NewsItem="050407122530.3e23mlbh.xml"/>
</NewsComponent>
<NewsComponent>
<NewsLines>
<HeadLine>Thai Airways unveils new corporate makeover,
aircraft</HeadLine>
</NewsLines>
<NewsItemRef NewsItem="050407113559.zziklpv1.xml"/>
</NewsComponent>
</NewsComponent>
</NewsItem>
</NewsML>

Jul 17 '05 #1
0 1560

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: marktm | last post by:
Hi- I am using the following code and want to retrieve an attributes value. I want to loop through the xml file and add the attribute values to an array. The line in question is marked with...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
2
by: fizzy | last post by:
i am fetching an xml document with the following structure: <?xml version="1.0" encoding="UTF-8"?> <DTCResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...
3
by: Sky Sigal | last post by:
I coming unglued... really need some help. 3 days chasing my tail all over MSDN's documentation ...and I'm getting nowhere. I have a problem with TypeConverters and storage of expandableobjects...
8
by: pradeepsarathy | last post by:
Hi all, Does the SAX parser has eventhandlers for parsing xml schema. Can we parse the xml schema the same way as we parse the xml document using SAX Parser. Thanks in advance. -pradeep
1
by: Martin Pöpping | last post by:
Hello, I´ve a problem with parsing a double value from an xml file. My code looks like this: int concept_id; double rank; XmlElement root = documentXMLString.DocumentElement; XmlNodeList...
0
by: Divya Prakash | last post by:
Hi But I am unable to parse all the nodes of the tree .....especially the subtree of the main tree It displays only the sibling not the subtree Regards Divya
1
by: WebCM | last post by:
There are lots of problems with XHTML parsing in PHP by XML functions. I've just solved most of them. However, how to get value of attribute with namespace? <input type="checkbox" id="something"...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.