Jump to content

Search the Community

Showing results for tags 'simplxml'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. I am trying to get a large (~60MB) XML file into a database and it is giving me fits. A sample record from the XML file looks like this: <entry> <ent_seq>1002090</ent_seq> <k_ele> <keb>お手盛り</keb> <ke_pri>news2</ke_pri> <ke_pri>nf33</ke_pri> </k_ele> <k_ele> <keb>御手盛り</keb> </k_ele> <r_ele> <reb>おてもり</reb> <re_pri>news2</re_pri> <re_pri>nf33</re_pri> </r_ele> <sense> <pos>&n;</pos> <gloss>making arbitrary decisions which benefit oneself</gloss> <gloss>self-approved plan</gloss> </sense> </entry> So, I can have 1 or more <k_ele> elements and within each I can have 1 or more <ke_pri> elements. I need to decide what to do with the record based on the the content of ke_pri elements. Same issue with <r_ele> elements. So, I read the XML with SimpleXML and then because I don't know if each r_ele and re_pri is an object over which I need to iterate or a variable I have ugly code that looks like this: if (is_object($r_ele)) { foreach ($r_ele as $reading_element) { $re_pri = $reading_element->re_pri; if (is_object($re_pri)) { foreach ($re_pri as $value) { switch ($value) { // decide what to do here } } } else { switch ($re_pri) { // decide what to do here } } } } else { $re_pri = $reading_element->re_pri; if (is_object($re_pri)) { foreach ($re_pri as $value) { switch ($value) { // decide what to do here } } } else { switch ($re_pri) { // decide what to do here } } } I know that there must be a more elegant way to do this and would love suggestions of how I can improve my code.
×
×
  • 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.