Jump to content

looping through attributes


Recommended Posts

I've searched through the tutorials etc but all seem to give examples of looping through elements. Also the xml file that I'm trying to use, small and all that it is, isn't perhaps formed the best way anyway but I'm stuck with the format because it is called from a flash swf that cannot be edited.

 

I'm trying to make a simple online form that loads an xml file (using php) to edit 'news' where each newsitem has a headline and then newstext (it also has a newsdate but that is no longer used)

 

Here is an example of the xml and you can see that each element has three attributes.---------<?xml version="1.0" encoding="UTF-8"?><News> <newsItem newsdate="" headline="Some Hotel or Other" itemtxt="Our last appearance here before the new year is on Saturday 18th Dec - etc. etc. "

/> <newsItem newsdate="" headline="Headline 2" itemtxt="news item 2 blurb here"

/> <newsItem newsdate="" headline="Headline 3" itemtxt="news item 3 blurb here"

/> <newsItem newsdate="" headline="Headline 4 " itemtxt="news item 4 blurb here "

/></News>

 

I am trying to make an xsl to use in a php form (just like the example on the tutorial) that will show the attributes of these newsitems so they can be edited and saved back to the xml file. I copied the tutorial example using PHP and that worked. However, I've tried editing the example to suit this xml but seen as the example code cycles through elements and not attributes I wasn't very successful and I can't seem to see an example of putting the values that are in quotes up for editing and saving back. Any help much appreciated.Thank you in advance for your time.

Link to post
Share on other sites
  • 2 weeks later...

I'd love to be writing a reply in here saying I've solved this but not joy. No one out there in the forum has any suggestins then?I've looked into just opening the file as a string. I'm familiar with string manipulation etc and could parse this small file myself into a form and do the same back and save the file. However, each php file function I tried

$html = implode('', file("test.xml"));

OR

echo file_get_contents("test.xml"); (this will work if I take out the xml tags and just have plain text in the file)

 

would not load the file as it has xml code so I'm back to looking at this method - which would work if I could only loop through the attributes - but no one here has any ideas on how to do that it seems?I realise that the xml code should have more elements and less atrributes but I would have thought this kind of thing would have come up before and someone would know the syntax for looping through attributes - No?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...