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

Strange structure to be parsed

Hi.

I want to parse this XML file:
-----------------
<doc>
<item>
<name>John Morrow</name>
<contact type="email">jo**@john.com</contact>
Blah blah
</item>
</doc>
--------------------

I'm able to get 'John Morrow':
$doc->getDocumentElement()->getElementsByTagName('item')->
getElementsByTagName('name')->item(0)->getFirstChild->getNodeValue;

But I don't know to get 'Blah Blah'. Any suggestion?

Thank you very much.

Jul 20 '05 #1
4 1408
* fr**********@europe.com wrote in comp.text.xml:
I want to parse this XML file:
-----------------
<doc>
<item>
<name>John Morrow</name>
<contact type="email">jo**@john.com</contact>
Blah blah
</item>
</doc>
--------------------

I'm able to get 'John Morrow':
$doc->getDocumentElement()->getElementsByTagName('item')->
getElementsByTagName('name')->item(0)->getFirstChild->getNodeValue;

But I don't know to get 'Blah Blah'. Any suggestion?


Well, it's the getLastChild of the item element, so something like

$doc
->getDocumentElement()
->getElementsByTagName('item')
->item(0)
->getLastChild
->getNodeValue;

should do, depending on whether your implementation supports such a
method. You did not say what you are using so I have to guess... Note
that e.g. XPath might be a better way to query for such information.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jul 20 '05 #2
There are so many tools to do that ... if I gave you a solution you
probably wouldn't be interested in it.

Jul 20 '05 #3
Bjoern Hoehrmann wrote:
* fr**********@europe.com wrote in comp.text.xml:
I want to parse this XML file:
-----------------
<doc>
<item>
<name>John Morrow</name>
<contact type="email">jo**@john.com</contact>
Blah blah
</item>
</doc>
--------------------

I'm able to get 'John Morrow':
$doc->getDocumentElement()->getElementsByTagName('item')->
getElementsByTagName('name')->item(0)->getFirstChild->getNodeValue;

But I don't know to get 'Blah Blah'. Any suggestion?

Well, it's the getLastChild of the item element, so something like

$doc
->getDocumentElement()
->getElementsByTagName('item')
->item(0)
->getLastChild
->getNodeValue;

should do, depending on whether your implementation supports such a
method. You did not say what you are using so I have to guess... Note
that e.g. XPath might be a better way to query for such information.


This does it, although I'd welcome critiques of the XPath expression:

--------------------- snip -------------------------
use XML::LibXML;
$parser = XML::LibXML->new();
$doc = $parser->parse_file("junkfile.xml");
$root = $doc->documentElement();
($node) = $root->findnodes("//item/child::node()[position()=last()]");
print "\"", $node->nodeValue, "\"\n";
--------------------- snip --------------------------

It prints:
"
Blah blah
"

Paul Allen
Jul 20 '05 #4
On 15 Feb 2005 16:04:54 -0800, fr**********@europe.com wrote:
Any suggestion?


Redesign the schema. That sort of mixed content is always a pain to
work with.

Jul 20 '05 #5

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

Similar topics

21
by: simon | last post by:
From my previous post... If I have a structure, struct sFileData { char*sSomeString1; char*sSomeString2; int iSomeNum1; int iSomeNum2;
3
by: Sameh Halabi | last post by:
Hi I have a strange problem in C , I hope someone may help with it . the problem is as follows : I have an existing big structure (that I can't change) which contains in it groups of...
7
by: dam_fool_2003 | last post by:
#include<stdio.h> int main(void) { unsigned int a=20,b=50, c = sizeof b+a; printf("%d\n",c); return 0; } out put: 24
10
by: junky_fellow | last post by:
I am trying to print the offset of a particulat member in a structure, but it's not working. I am using the following expression to print the offset. &(struct my_struct *)0->member_name ...
8
by: Carlos | last post by:
I have a strinf with comma separated field. Is is possible to convert it to a Structure ? Thanks
3
by: GeLLcheN | last post by:
Hello everybody, I've got a little (endian) problem. I'm programming a network-based application, in which I'll use structs, interpreting ethernet packets. My intention is to read the stream...
3
by: TheSteph | last post by:
Hi, I have a small serializable struct : public struct TestStruct { public string Title; public int Age; public string Name;
112
by: Prisoner at War | last post by:
Friends, your opinions and advice, please: I have a very simple JavaScript image-swap which works on my end but when uploaded to my host at http://buildit.sitesell.com/sunnyside.html does not...
6
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
Yesterday Visual Studio gave me a strange error both at compiletime and at designtime that had no obvious connection to anything I had changed recently. After some effort tracking down the problem...
6
by: jdmuys | last post by:
Hi, I have a strange bug in my code, which I managed to reduce to the tiny C++ program below. The compiler reject the "class1<Type>::insideStruct *p2;" declaration with the following error...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.