473,221 Members | 1,722 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,221 software developers and data experts.

Parsing - Reading data within a tag

Hi,

I am new to XML and PHP and have a question that I hope someone could
answer.

Some background on my problem.
I am receiving an XML message over TCP/IP and need to access data
within the tags of the message.

Message example:
<message title="begin"
no="1"><description>Start</description></message>
Now I know I can get the data from the description tag by:

$xmlstr =<<<EOT
<message title="begin"
no="1"><description>Start</description></message>
EOT;

$xml = simplexml_load_string($xmlstr);
echo ($xml->description[0]);
My question is, how do I access 'title' or 'no' ?
Is it possible?

I cannot change the format of the data sent to me.
I am using PHP 5.0.5

Any help is appreciated.

Also, is this the best way of parsing the XML message?

Thank you

Steve

Oct 11 '05 #1
1 1380
Steve said the following on 11/10/2005 21:35:
Some background on my problem.
I am receiving an XML message over TCP/IP and need to access data
within the tags of the message.

Message example:
<message title="begin"
no="1"><description>Start</description></message>
Now I know I can get the data from the description tag by:

$xml = simplexml_load_string($xmlstr);
echo ($xml->description[0]);
My question is, how do I access 'title' or 'no' ?
Is it possible?

http://www.php.net/simplexml
Also, is this the best way of parsing the XML message?


The SimpleXML functions convert an XML document into a nested data
structure in one operation, but this could require a fair chunk of
memory, depending on the size and complexity of the XML data.

The basic XML functions, however, provide an event-based parsing scheme.
i.e. the parser reads from top to bottom, and every time an element is
opened or closed, a user-defined function is called. This allows you to
perform necessary processing without chewing up large amounts of memory.

See http://www.php.net/manual/ref.xml.php

--
Oli
Oct 11 '05 #2

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

Similar topics

4
by: ralphNOSPAM | last post by:
Is there a function or otherwise some way to pull out the target text within an XML tag? For example, in the XML tag below, I want to pull out 'CALIFORNIA'. ...
3
by: Pir8 | last post by:
I have a complex xml file, which contains stories within a magazine. The structure of the xml file is as follows: <?xml version="1.0" encoding="ISO-8859-1" ?> <magazine> <story>...
10
by: Tony | last post by:
I'm wondering if anyone has run any tests to compare the speed of parsing XML vs text in simple lists - such as: <?xml version="1.0" encoding="ISO-8859-1"?> <users> <user>User 1</user>...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
5
by: timslavin | last post by:
Hi, I'm trying to do something with PHP and I'm not 100% familiar with PHP as I am with VBScript. So if you could bear with me on what is likely a stupid question, I'd appreciate it! I have a...
3
by: Cuong.Tong | last post by:
Greeting, I am writing my own web server and having some problme parsing the the mulitpart/form-data stream that is sent from the browsers. I have a form looks something like this <form...
4
by: Neil.Smith | last post by:
I can't seem to find any references to this, but here goes: In there anyway to parse an html/aspx file within an asp.net application to gather a collection of controls in the file. For instance...
15
by: Lone Wolf | last post by:
I'm trying to get data through my serial port from a CMUcam. This gizmo tracks a color and returns a packet of data. The packet has nine data points (well, really eight since the first point is...
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
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...
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
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
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.