Jump to content

Extract data from XML Element


mbk

Recommended Posts

Hi All,

 

Another new issue I have now!

 

I have the following XML code and am needing to extract certain parts of the element <contact> however there are various different fields, and the field I need is also repeated in another element in the same page.

 

I need to extract the position, the club and nationality from the following, but dont really know where to begin.

 

<Contact FirstName="Jim" Surname="Jones" Age="32" Position="Forward" Club="Bury" Weight="12st 3lb" Height="6ft 2in" Appearances="28" Sub="14" Goals="22" SquadNumber="16" Nationality="Jamaican">
<Related FirstName="Gary" Surname="Jones" Age="38" Position="Forward" Club="Tranmere Rovers" Weight="13st 1lb" Height="6ft 4in" Appearances="2" Sub="14" Goals="4" SquadNumber="12" Nationality="Welsh">
</Related>
</Contact>

 

All help appreciated.

Link to comment
https://forums.phpfreaks.com/topic/192401-extract-data-from-xml-element/
Share on other sites

I have looked through the information that you directed me through but there doesnt seem to be a way documented that will allow me to search within the element and extract the specific data, as they arent actual children within the element.

 

I am thinking it may be some sort of regex based on the element that needs to be done??

I have looked through the information that you directed me through but there doesnt seem to be a way documented that will allow me to search within the element and extract the specific data, as they arent actual children within the element.

 

I am thinking it may be some sort of regex based on the element that needs to be done??

 

attributes()

http://www.php.net/manual/en/simplexmlelement.attributes.php

Schweppes - thanks for the info and for the link.

 

I still havent managed to solve this though.  I am looking to get a value from within an element that is not surrounded by the <>  but is a string always placed between the same two points, the start point is an = and the close point is Club.

 

I also need to remove the quotes surrounding the text to be selected.

 

I think I will need a Regex statement to complete this, but am not sure.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.