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

preg_matching an XML node not working

Does anyone know why the following isn't working, I'm losing my mind over this.

[PHP]

//if this is part of the xml file your loading
$str = '<xmlRoot>

<sample id="1">
<Company>GSK</Company>
<JPG_400>1gskmisc_400.jpg</JPG_400>
</sample>

<sample id="2">
<Company>GSK</Company>
<JPG_725>1gskmisc_725.jpg</JPG_725>
</sample>
</xmlroot>';

//this dosn't match the first node only
preg_match('/<sample id\="1">[\S\s]*<\/sample>/',$str,$a);

print_r($a[0]);


[/PHP]
Jan 8 '08 #1
1 1056
Well, I fianlly got it.

this is the magic pattern:

[PHP]

$tag = 'sample id="1"';
$base = 'sample';

preg_match('/<' . preg_quote($tag) . '>([^`]*?)<\/' . $base . '>/i',$str,$a);

print_r($a[0]);

[/PHP]
Jan 8 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ralf Wahner | last post by:
Dear Masters of XSLT Could I ask you for a clue on the following question? I'd like to use XSLT to transform an XML source file to LaTeX. In the following small example the <para> Element...
4
by: Rolf Kemper | last post by:
Hi All, ned help on the example below. It works fine for msxml3/4 but has problems with saxon. Saxon complains "can not find matching function ..... " My target is to write style sheets...
5
by: reddy | last post by:
I am trying to insert a node into an XMLFile. using XMLTextwriter. My Question is Is it possible to do without using XMLDocument. Because its loading all the the file into memory. I just want to...
3
by: Francois Grieu | last post by:
Given that next is the first field in struct node, and head is a pointer to node, does assigning ((node*)&head)->next safely assign head ? Illustration (this code works on many platforms)...
1
by: timtos | last post by:
I am working on a custom treeView and have some problems with a) node.Bounds.Width b) concatenate strings drawn with DrawString(...) a) I want to highlight a selected node and used the...
16
by: Joel Byrd | last post by:
I am having this ridiculous problem of trying to set the innerHTML of a div node. It works in all other browsers, but internet explorer is giving me an "Unknown runtime error". This is actually...
0
by: XML newbie: Urgent pls help! | last post by:
HI, I am working on VB.Net.My program connects to the remote host, once the login values are verified, it sends the SessionID. My problem is Although in "Logindom" variable( in the Auto window),...
0
by: RJN | last post by:
Hi I have to read an xml and add the node elements into a hashtable with nodename as key and nodetext as value. If the selected node has childnodes, then value should go as an array. for eg.,...
0
by: HP17 | last post by:
Hi all, I am a bit desperate already trying to display a XML file using XSLT. I create a table and use <xsl:for-each> to extract every element node. This is working fine. What I want now is so...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.