Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Posts
    152
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Cool Searching XML File

    Hello all,

    I have an XML file with around 20,000 records. For each record there is an element:

    <commons:Country>US</commons:Country>


    Now I would like to search through all records and return the country codes ideally in a separate text file...I am using Notepad++

    Any ideas on how i can proceed?

    thanks in advance,
    Andy

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,311
    Thanks
    23
    Thanked 612 Times in 611 Posts
    You didn't give me enough to give you exact code, but here is a general method:
    This is in php and is the only way I know.

    First get your file as variable $xml:
    PHP Code:
    $feed file_get_contents("PUT THE URL HERE");
    $xml = new SimpleXmlElement($feed); 
    then we use a foreach loop. You will have to drill down the elements until you hit <record>
    PHP Code:
    foreach ($xml->records->record as $entry
    Then inside of the loop:
    PHP Code:
    $namespaces $entry->getNameSpaces(true);
    $commons $entry->children($namespaces['commons']);
      echo 
    $commons ->Country
    Should do it. Please give me feed back on this.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •