issues for parsing xml data in swift 5 with NSRegularExpression

Hello !

i have some issues for extract datas from an HTTP request, please can you help me ??

1)I send a request for asking the datas from a local device :

Code Block language
http://192.168.2.1/data/

2) below the device send this result in xml

Code Block language
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Index of /data/100CAMBX/</title>
</head>
<body>
<h2>Index of /data/100CAMBX/</h2>
<div class="list">
<table summary="Directory Listing" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th class="n">Name</th>
<th class="m">Last Modified</th>
<th class="s">Size</th>
<th class="t">Type</th>
</tr>
</thead>
<tbody>
<tr class="d">
<td class="n">
<a href="../">Parent Directory</a>/</td>
<td class="m">&nbsp;</td>
<td class="s">- &nbsp;</td>
<td class="t">Directory</td>
</tr>
<tr>
<td class="n">
<a href="Video1.MOV">CMBX0007.MOV</a>
</td>
<td class="m">2000-Jan-01 22:46:48</td>
<td class="s">1.5G</td>
<td class="t">video/quicktime</td>
</tr>
<tr>
<td class="n">
<a href="CMBX0009.MOV">CMBX0009.MOV</a>
</td>
<td class="m">2000-Jan-13 08:28:24</td>
<td class="s">92.4M</td>
<td class="t">video/quicktime</td>
</tr>
<tr>
<td class="n">
<a href="CMBX0010.MOV">CMBX0010.MOV</a>
</td>
<td class="m">2021-Mar-10 16:53:18</td>
<td class="s">1.8M</td>
<td class="t">video/quicktime</td>
</tr>
</tbody>
</table>
</div>
<div class="foot">lighttpd/1.4.41</div>
</body>
</html>

3) i want to extract in this file theses 5 values integrate in the <body>

Code Block language
<th class="n">Video1.MOV</th>. //title of the video
<th class="n">CMBX0007.MOV</th>. // filename video
<th class="m">2000-Jan-01 22:46:48</th> //date&time
<th class="s">1.5G</th> // video size
<th class="t">Type</th> // video type

I need also to create an loop function for getting these 5 parameters for each videos files and store them in a structure.

everybody can help me please ?


Parsing XML (or, worse, HTML) with regular expressions is an exercise fraught with danger. For example, your code might seem to work just fine until the XML contains an escaped character )-:

A better option is to use a dedicated XML parser. For something like this NSXMLParser is a good place to start. There’s tonnes of docs, sample code, and general Internet lore about this API.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Hi The Eskimo !

I saw this functionality and hesitate between these two

many thanks for your reply

best regards
Jim


issues for parsing xml data in swift 5 with NSRegularExpression
 
 
Q