mbk Posted February 17, 2010 Share Posted February 17, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/192401-extract-data-from-xml-element/ Share on other sites More sharing options...
premiso Posted February 17, 2010 Share Posted February 17, 2010 You can use the domxpath or the simple_xml functions to parse XML data effectively. I would suggest looking into those. Quote Link to comment https://forums.phpfreaks.com/topic/192401-extract-data-from-xml-element/#findComment-1013786 Share on other sites More sharing options...
mbk Posted February 17, 2010 Author Share Posted February 17, 2010 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?? Quote Link to comment https://forums.phpfreaks.com/topic/192401-extract-data-from-xml-element/#findComment-1013843 Share on other sites More sharing options...
SchweppesAle Posted February 17, 2010 Share Posted February 17, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/192401-extract-data-from-xml-element/#findComment-1013960 Share on other sites More sharing options...
mbk Posted February 21, 2010 Author Share Posted February 21, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/192401-extract-data-from-xml-element/#findComment-1015841 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.