XML syntax validation in Freeswitch

It happens sometimes while modifying or editing any XML file accidentally we put some extra character or missing some closing tags.

In such cases it's very hard to find the exact file where we did that mistake or in which file we missed something. I am taking example of FreeSWITCH.

When you do such kind of mistake in FreeSWITCH it gives error like this while executing reloadxml in fs_cli.

 freeswitch@internal> reloadxml  
 +OK [[error near line 413]: missing >]  

And while restarting / starting  Freeswitch it will just fail to start or it will give you error something like this.

 root@juned-HP:~# freeswitch  
 2015-10-02 11:50:45.718334 [INFO] switch_event.c:685 Activate Eventing Engine.  
 2015-10-02 11:50:45.719183 [WARNING] switch_event.c:656 Create additional event dispatch thread 0  
 Cannot Initialize [[error near line 413]: missing >]  







As a solution of this problem there is tool xmllint which is used to check xml syntax errors. you just need to combine it with some Linux commands like find, here is the example.

I've forgot to close one of xml tag in dialplan directory then i will run command like this

root@juned-HP:~# find /usr/local/freeswitch/conf/dialplan/ -name "*.xml" -type f -exec xmllint --noout '{}' \;  

And the result you will be getting is,

/usr/local/freeswitch/conf/dialplan/default.xml:23: parser error : attributes construct error  
     <action application="bridge" data="sofia/gateway/asterisk/$1"/  
                                    ^  
 /usr/local/freeswitch/conf/dialplan/default.xml:23: parser error : Couldn't find end of Start Tag action line 23  
     <action application="bridge" data="sofia/gateway/asterisk/$1"/  
                                    ^  

So here we can easily figure out that we have missed ' > ' tag here.

You can do a lot with xmllint command.  However sometimes results are not 100% perfect. I'll update the docs as soon as i get something more on this.

Hope this helps !



No comments:

Post a Comment

Pages