I'm working on a self proclaimed cool project where one would extract Xml data with Sql syntax.
<?ml version="1.0" encoding="utf-8"?>
<data attr1='some data' attr2='some data'>
<personalData>
<name>Mario</name>
<lastName>Legenda</lastName>
<birthData>
<day>18</day>
<month num="06">june</month>
<godina>1986</godina>
</birthData>
<sex>M</sex>
<death>N/A</death>
<OIB>569874125369</OIB>
<JMBG>25698745212</JMBG>
<misc>
<employed>n</employed>
<student>n</student>
<intelligence>n</intelligence>
<tolerant>n</tolerant>
<specialPowers>n</specialPowers>
<married>n</married>
<relationshipStatus>n</relationshipStatus>
<socialLife>n</socialLife>
</misc>
</presonalData>
</data>
To fetch the entire 'data' tag, sql would be SELECT data FROM path/to/file/data.xml
. After certains classes verify if the syntax is correct, the data fetching starts.
I want to do this project with regex, not with Dom, SimpleXml or other beacuse i wish to learn regex better. So... I'm trying to evaluate if the 'data' tag in the specified xml exists. I do this with...
preg_match('#<data\s?([\w]+=[\w]+\s?)+?>#i', $XmlAsString, $match);
The ?
operator is giving me trouble. It doesn't seem to know that \s is an empty space. so he's only giving me the attr2 attribute in the $match
array.