473,657 Members | 2,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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->getDocumentEle ment()->getElementsByT agName('item')->
getElementsByTa gName('name')->item(0)->getFirstChil d->getNodeValue ;

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

Thank you very much.

Jul 20 '05 #1
4 1413
* fr**********@eu rope.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->getDocumentEle ment()->getElementsByT agName('item')->
getElementsByT agName('name')->item(0)->getFirstChil d->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
->getDocumentEle ment()
->getElementsByT agName('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****@h oehrmann.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**********@eu rope.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->getDocumentEle ment()->getElementsByT agName('item')->
getElementsBy TagName('name')->item(0)->getFirstChil d->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
->getDocumentEle ment()
->getElementsByT agName('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("ju nkfile.xml");
$root = $doc->documentElemen t();
($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**********@eu rope.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
6643
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
2062
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 variables that is repeated . typedef struct big_struct { ..... ..... char a1;
7
1925
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
4031
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 What's wrong with this ? If I use, &((struct my_struct *)0)->member_name, it works. But it seems
8
4527
by: Carlos | last post by:
I have a strinf with comma separated field. Is is possible to convert it to a Structure ? Thanks
3
1466
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 directly and transport to the right struct. But this seems to be not so simple: Here's a sample code demonstrating my problem:
3
2211
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
4657
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 work. To rule out all possible factors, I made up a dummy page for an index.html to upload, along the lines of <html><head><title></title></ head><body></body></html>.; the image-swap itself is your basic <img src="blah.png"...
6
3336
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 I discovered first a workaround, then the real cause of the problem. I would like to understand why what I am doing is frowned upon by Visual Studio and how to do this properly. My application is in one solution; supporting libraries including...
6
4518
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 message: /.../main.cpp:23: error: expected ';' before '*' token
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8606
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.