0

For My website Internal Processing I am storing some data in xml(or it may not look like XML, I am trying to store which will be better to parse and store, I come up till this)

XML is only for structure,the below code/xml is stored in post-field, which is MySQL database. I am looking for better format if any, and how to parse it.

This XML was created in my CMS(Drupal), although it has nothing to do with Drupal, this is PHP question.

<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 125 75"><defs><style>.cls-1{font-size:57.6px;}.cls-1,.cls-2{fill:#f80000;font-family:MicrosoftYaHeiUI-Bold, Microsoft YaHei UI;font-weight:700;}.cls-2{font-size:33.6px;}</style></defs><text class="cls-1" transform="translate(13.28 63.08)">19</text><text class="cls-2" transform="translate(77.56 24.81) scale(0.86 1)">c</text></svg>
<nav-head>Salamandar</nav-head>
<post><id>12</id><link>url/how-to-pet</link><title>How to Pet</title></post>
<post><id>13</id><link>url/how-to-feed</link><title>How to Feed</title></post>
<post><id>14</id><link>url/salamandar/cage/which-cage</link><title>Which Cages</title></post>
<post><id>17</id><link>url/salamandar/type/different-types</link><title>Types of Salamandar</title></post>
<post><id>19</id><link>url/salamandar/type/poisonous-breed</link><title>Poisonus Breed</title></post>
<nav-header>Keeping Safe</nav-header>
<post><id>21</id><link>url/salamandar/safety/safety-children</link><title>Keep out of Children</title></post>
<post><id>24</id><link>url/salamandar/safety/keep-out-of-dogs</link><title>Keep out of Dogs</title></post>
<post><id>27</id><link>url/salamandar/safety/keep-out-of-reptiles</link><title>Keep out of Reptiles</title></post>
<post><id>34</id><link>url/redis/salamandar/safety/fungus-free</link><title>Keep fungus free</title></post>

The above is the code/XML is stored for creating sidebar, I Want to get the above data to PHP array.

Is the above possible to get into an array format, or should I store another way.

<nav-header> is the sidebar header. The above structure or XML will create sidebars markup as many ID(article) ids available, add CSS classes, and for each sidebar, only add one active css class for that sidebar.

Please give some suggestive comment?

  1. Can the above be parsed to PHP array
  2. Is there any better form available which will make the above objective easier for PHP.

My Website/App is in building phase, please suggest, This question has nothing to do with Drupal or any CMS, it is merely PHP question. Thanks

  • Depending on where you store it, a DB would be better, but if not then JSON. If you post a question with how you get data someone can show a good way to store and parse. What you show is probably not a good way. – AbraCadaver May 24 '21 at 00:41
  • Yes, you can parse xml in php to get an array. You could then convert it either to a json file or to a database, both of which are faster than parsing xmls in php, but what you end up doing depends on how you plan on using it. – Ant May 24 '21 at 00:46
  • [DomDocument](https://www.php.net/manual/en/class.domdocument.php) will parse it fine https://3v4l.org/8XcXp (example, you would target things more) – Lawrence Cherone May 24 '21 at 00:52
  • 1
    There is also php's [simplexml](https://www.php.net/manual/en/book.simplexml.php) and [xml_parse](https://www.php.net/manual/en/function.xml-parse.php) – Ant May 24 '21 at 00:53
  • @LawrenceCherone thanks, please add answer, I will accept – Brown Paul May 24 '21 at 00:59
  • 1
    its a dupe, its essentually html, be it a
    , or a dom parser doesnt really mind
    – Lawrence Cherone May 24 '21 at 01:02

0 Answers0