Hi xaled,

There should be no problem with colons in element names (libxml will produce some errors, because namespaces are not handled by the xml module and the prefix is simply considered as part of the element name, but they can be ignored), your issue seems to be caused by something else. What errors or other relevant messages do the logs produce? I do spot on the other hand a wrong access to the first element when adding the attribute, which should look like "$xml(xml_s/tns:messageType.attr/xmlns:tns)" but the document should still be created fine without that attribute.

As for adding the encoding, you could initialize the $xml variable directly with the required XML declaration, like this:

$xml(xml_s) = '<?xml version="1.0" encoding="UTF-8"?><tns:messageType></tns:messageType>';

Formatted output is not possible currently, you can open a feature request on Github regarding this, but if you really need the XML document to actually contain the indentation characters, you could do so explicitly when inserting the nodes (as in the documentation example).

Regards,

Vlad Patrascu
OpenSIPS Developer
http://www.opensips-solutions.com

On 08/20/2017 07:08 PM, xaled wrote:

Hi,

Just tried the new xml module and have some issues with colon in element names. Should I use some escape magic for colons with opensips xml module?

Another question is how to add encoding="UTF-8" to have it like this - <?xml version="1.0" encoding="UTF-8"?>

It would be also great to have formatted XML output. Something like format parameter in toString method of XML::LibXML::Document in perl.

test:/usr/local/etc/opensips # /usr/local/sbin/opensips -V

version: opensips 2.3.1 (x86_64/linux)

flags: STATS: On, DISABLE_NAGLE, USE_MCAST, SHM_MMAP, PKG_MALLOC, F_MALLOC, FAST_LOCK-ADAPTIVE_WAIT

ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 65535

poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.

git revision: 72fa146

main.c compiled on 18:53:05 Aug 16 2017 with gcc 4.8

$xml(xml_s) = "<tns:messageType></tns:messageType>";

$xml(xml_s.attr/xmlns:tns) = "http://test.org/abc/params/xml/abc";;

$xml(xml_s/tns:messageType) = "<tns:crtg></tns:crtg>";

$xml(xml_s/tns:messageType/tns:crtg) = "<tns:ControlIndicators></tns:ControlIndicators>";

$xml(xml_s/tns:messageType/tns:crtg/tns:ControlIndicators) = "<tns:Factor>5</tns:Factor>";

xlog("XML_TEST: $xml(xml_s)\n");

2017-08-20T17:46:38.320273+02:00 test /usr/local/sbin/opensips[32422]: XML_TEST: <?xml version="1.0"?>#012<messageType/>

The final XML should be like this:

<?xml version="1.0" encoding="UTF-8"?>

<tns:messageType xmlns:tns="http://test.org/abc/params/xml/abc";>

  <tns:crtg>

    <tns:ControlIndicators>

     <tns:Factor>5</tns:Factor>

    </tns:ControlIndicators>

  </tns:crtg>

</tns:messageType>

Thanks,

xaled



_______________________________________________
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users

_______________________________________________
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users

Reply via email to