473,834 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read xml file from last entry

134 New Member
hi

i have a xml file which has transaction details of the users.

I m inserting data using appendChild() from php.

While displaying i need to display the last 5 entry or single entry or the whole entries descending using php.

Is there anyway to read the xml file from the lastentry using php...


regards
vijay
Sep 2 '09 #1
16 4321
Dormilich
8,658 Recognized Expert Moderator Expert
you can read XML in PHP either by DOMDocument or SimpleXML
Sep 2 '09 #2
vjayis
134 New Member
Yes i can.,

but i need to read the entries descendingly.. i cant figure it out from the definitions..

any suggestions..
Sep 2 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
@vjayis
sorted or as they appear in the file? (the elements are usually sorted in document order, so you can read the NodeList and do any DOM functions with it that you need)

you may consider reading them into an array and apply any array functions you need. other than that you may use XSLT (which has a sort command).
Sep 2 '09 #4
vjayis
134 New Member
here is my file contents

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <trans>
  3.     <transfer>
  4.         <id>1</id>
  5.         <acno>B900326</acno>
  6.         <amount>10000</amount>
  7.         <type>Credit</type>
  8.         <memo>(Credit)memo!@#$%^&amp;*()_+|}{":?&gt;&lt;</memo>
  9.         <fee>0</fee>
  10.         <ft_acno>Admin</ft_acno>
  11.         <batch>1</batch>
  12.         <tempbalance>10000</tempbalance>
  13.         <date>2009-07-11</date>
  14.         <time>1247288167</time>
  15.     </transfer>
  16.     <transfer>
  17.         <id>2</id>
  18.         <acno>P587178</acno>
  19.         <amount>98</amount>
  20.         <type>Credit</type>
  21.         <memo>test</memo>
  22.         <fee>2</fee>
  23.         <ft_acno>B900326</ft_acno>
  24.         <batch/>
  25.         <tempbalance>98</tempbalance>
  26.         <date>2009-07-11</date>
  27.         <time>1247288200</time>
  28.     </transfer>
  29.     <transfer>
  30.         <id>3</id>
  31.         <acno>B900326</acno>
  32.         <amount>100</amount>
  33.         <type>Debit</type>
  34.         <memo>test</memo>
  35.         <fee>0</fee>
  36.         <ft_acno>P587178</ft_acno>
  37.         <batch/>
  38.         <tempbalance>9900</tempbalance>
  39.         <date>2009-07-11</date>
  40.         <time>1247288200</time>
  41.     </transfer>
  42.     <transfer>
  43.         <id>4</id>
  44.         <acno>P662318</acno>
  45.         <amount>196</amount>
  46.         <type>Credit</type>
  47.         <memo>testing</memo>
  48.         <fee>4</fee>
  49.         <ft_acno>B900326</ft_acno>
  50.         <batch/>
  51.         <tempbalance>196</tempbalance>
  52.         <date>2009-07-13</date>
  53.         <time>1247460597</time>
  54.     </transfer>
  55.     <transfer>
  56.         <id>5</id>
  57.         <acno>B900326</acno>
  58.         <amount>200</amount>
  59.         <type>Debit</type>
  60.         <memo>testing</memo>
  61.         <fee>0</fee>
  62.         <ft_acno>P662318</ft_acno>
  63.         <batch/>
  64.         <tempbalance>9700</tempbalance>
  65.         <date>2009-07-13</date>
  66.         <time>1247460597</time>
  67.     </transfer>
  68.  </trans>
  69.  
there are totally 5entry's in it.

i need to display it in descending order.

I had found an way to display it in the descending order as follows..

Expand|Select|Wrap|Line Numbers
  1. <?
  2. $filename='test.xml';
  3.  
  4. $data = simplexml_load_file($filename);
  5.  
  6. $c=count($data->transfer);
  7.  
  8. for($i = $c; $i>=0 ; $i--){
  9.  
  10.   echo $i.'-'.$data->transfer[$i]->time.'<br>';
  11.  
  12. }
  13. ?>
  14.  
which results in giving the the output as follows

6-
5-1251866501
4-1251866308
3-1251804653
2-1251802528
1-1251802455
0-1251802411


Did i followed the correct way?

or is there an anyother formatted approach for this one?

And can i make a search and display results in xml file like doing in sql...

if there give me some ideas..
Sep 2 '09 #5
Dormilich
8,658 Recognized Expert Moderator Expert
Expand|Select|Wrap|Line Numbers
  1. // last index is usually 1 lower than length
  2. for($i = $c-1; $i>=0 ; $i--){
And can i make a search and display results in xml file like doing in sql...
you can use XPath to search if you want to stay inside XML or use PHP to look inside the XML string, depending on the search requirements.
Sep 2 '09 #6
vjayis
134 New Member
ya thats what i m asking.,

how can search inside xml file using php without using any loops.

any examples..
Sep 2 '09 #7
Dormilich
8,658 Recognized Expert Moderator Expert
@vjayis
what do you need loops for?
Sep 2 '09 #8
vjayis
134 New Member
k fine if i need to display items with date='2009-07-11' from the above example means how can i do that..
Sep 2 '09 #9
Dormilich
8,658 Recognized Expert Moderator Expert
guess I’d use XPath (you could also do a text search, but it would be more complicated to get the items…)

XPath (get all items with a given date)
Expand|Select|Wrap|Line Numbers
  1. //transfer[date="_date_"]
Sep 2 '09 #10

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

Similar topics

15
5906
by: Ridimz | last post by:
When use ifstream, how do I ignore the last line of a file if it doesn't contain any information? Thanks in advance, Ridimz
5
1669
by: Stanley Yue | last post by:
I made a map like this: typedef struct { char * Source; bool DirFlag; } RegInfo_t; struct Comp {
5
2886
by: Julia | last post by:
Strategy to read part of XML log file Hi, My log file will contains entries formatted as XML(i use this format since some time i would like to log entire objects) I am going to use FileSystemWatcher in order to detect when changes occur to the file and now I am facing a problem reading the last added node I came to the following strategy:
2
5444
by: krukinews | last post by:
Hi, I'm trying to write small program that reads events from computer and stores them in SQL database. But I don't know hove to read logs for let's say last 24 hours, one solution is to read all events in event log and then check time. foreach(EventLogEntry Entry in logSystem.Entries) { //
1
3807
by: MikeY | last post by:
Hopefully someone can help, I have a listview box where I display my desired files. I single click on the desired file to be renamed and I rename it with a new name. My problem arises when the new name gets displayed through refreshing of my loop and display function. The problem is that when, if I rename the last file entry, everything appears to display fine. If I rename a file above the last entry (bottom entry), two of the new file...
1
5363
by: vkrasner | last post by:
It works with VS2003 and does not in VS2005: in VS2003 : string sMyvalue = ConfigurationSettings.AppSettings; in VS2005 (does not work!!) string sMyvalue = ConfigurationManager.AppSettings; Anybody able to give me idea how-to read by C# element which I add to the machine.config into the new single section?
5
5125
by: Sumana | last post by:
Hi All, We developed our project on VC++.Net console application to create image of disk and to write the image We are having problem with reading and writing the sector beyond 6GB Disk or Partition we are using ReadFile , WriteFile and setFilePointerEx to read and write the sectors and we are reading/writing 102400 sectors together, even we have reduced the sectors still it is not able to read or write, our program is working fine...
8
1891
by: kepioo | last post by:
I currently have an xml input file containing lots of data. My objectiv is to write a script that reports in another xml file only the data I am interested in. Doing this is really easy using SAX. The input file is continuously updated. However, the other xml file should be updated only on request. Everytime we run the script, we track the new elements in the input file and report them in the output file.
2
1644
by: Brad King | last post by:
Hello Everyone, I am having trouble reading a file. My eventual plan is to read in the file, fix a formatting problem with a regex and export the changed data to a new file. However my importing skills are not working. Can anyone help me in the right direction? I believe my problem is that I have set lengths for the import and what I should have done is look for the next space. Can anyone show me a snippet that looks for the next...
0
10793
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
10509
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
10219
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...
0
9331
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7757
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
6954
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
5626
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5793
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3977
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.