Reputation: 1
i need your support formatting the following sample text from its current format to xml format using xquery: sample text to be parsed:
INTERNATIONAL MOBILE SUBSCRIBER IDENTITY = 001010000000597 TEMPORARY MOBILE SUBSCRIBER IDENTITY = N ACTIVATION STATUS = A
to be in the following xml format
<item>
<paramName>INTERNATIONAL MOBILE SUBSCRIBER IDENTITY</paramName>
<paramValue>001010000000597</paramValue>
</item>
<item>
<paramName>TEMPORARY MOBILE SUBSCRIBER IDENTITY</paramName>
<paramValue>N</paramValue>
</item>
<item>
<paramName>ACTIVATION STATUS</paramName>
<paramValue>A</paramValue>
</item>
please any one can help me in such case,
Thanks
Upvotes: 0
Views: 104
Reputation: 167716
Here is an example using XQuery 3.1 and the analyze-string
function:
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method 'xml';
declare option output:indent 'yes';
declare variable $input-string as xs:string external := 'INTERNATIONAL MOBILE SUBSCRIBER IDENTITY = 001010000000597 TEMPORARY MOBILE SUBSCRIBER IDENTITY = N ACTIVATION STATUS = A';
analyze-string($input-string, '(.+?) = (\S+)')//fn:match
!
<item>
<paramName>{ fn:group[@nr = 1] => normalize-space() }</paramName>
<paramValue>{ fn:group[@nr = 2] => normalize-space() }</paramValue>
</item>
https://xqueryfiddle.liberty-development.net/nbUY4kq
Using XQuery 3.0 without using the =>
operator the question looks like this:
declare variable $input-string as xs:string external := 'INTERNATIONAL MOBILE SUBSCRIBER IDENTITY = 001010000000597 TEMPORARY MOBILE SUBSCRIBER IDENTITY = N ACTIVATION STATUS = A';
analyze-string($input-string, '(.+?) = (\S+)')//fn:match
!
<item>
<paramName>{ normalize-space(fn:group[@nr = 1]) }</paramName>
<paramValue>{ normalize-space(fn:group[@nr = 2]) }</paramValue>
</item>
Upvotes: 0