0

I am trying to generate the following xml output:

<OrderDataUpdate xmlns=”http://www.metasolv.com/OMS/OrderDataUpdate/2002/10/25”>
<TetheringType>IE Tethering</TetheringType>
</OrderDataUpdate>

But instead I get this(note the text content for TetheringType is not populated).

<OrderDataUpdate xmlns="http://www.metasolv.com/OMS/OrderDataUpdate/2002/10/25">
<TetheringType/>
</OrderDataUpdate>

My input XML:

<soapenv:Envelope 
     xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:serviceLookUpResponse 
           xmlns:ser="http://xmlns.oracle.com/communications/inventory/webservice/service">
         <com:requestContext xsi:nil="true" 
            xmlns:com="http://xmlns.oracle.com/communications/inventory/webservice/common"/>
         <com:messages xmlns:com="http://xmlns.oracle.com/communications/inventory/webservice/common"
         >Success</com:messages>
         <service>
            <id>12021409</id>
            <name>1</name>
            <description xsi:nil="true"/>
            <state>in service</state>
            <startDate>2013-11-06T00:13:02.000-06:00</startDate>
            <specification>
               <name>HSPA Wireless Service</name>
               <entityType>Service</entityType>
               <description xsi:nil="true"/>
               <startDate>2010-05-13T00:00:01.000-05:00</startDate>
               <endDate xsi:nil="true"/>
            </specification>
            <parties>
               <id>1-3BQJ7K</id>
               <name>MTSC NETWORK SRV WIRELESS-CELLULAR</name>
               <description xsi:nil="true"/>
            </parties>
            <configurations>
               <version>31</version>
               <previousVersion>30</previousVersion>
               <id>Se_12021409_31</id>
               <name>Se_12021409_31</name>
               <description xsi:nil="true"/>
               <state>completed</state>
               <startDate>2015-01-21T15:03:52.000-06:00</startDate>
               <endDate xsi:nil="true"/>
               <configurationItems>
                  <name>Entitlement</name>
                  <index>0</index>
                  <resourceAssignment>
                     <state>assigned</state>
                     <resource>
                        <id>Tethering</id>
                        <name xsi:nil="true"/>
                        <description>Tethering Entitlement</description>
                        <specification>
                           <name>Entitlement</name>
                           <entityType>Custom Network Address</entityType>
                           <description xsi:nil="true"/>
                           <startDate>2015-01-15T00:00:01.000-06:00</startDate>
                           <endDate xsi:nil="true"/>
                        </specification>
                     </resource>
                  </resourceAssignment>
                  <resourceReference xsi:nil="true"/>
                  <characteristics>
                     <name>Tethering Type</name>
                     <value>IE Tethering</value>
                  </characteristics>
               </configurationItems>               
            </configurations>
         </service>
      </ser:serviceLookUpResponse>
   </soapenv:Body>
</soapenv:Envelope>

Xquery:

declare namespace soap = "http://schemas.xmlsoap.org/soap/envelope/";
declare namespace ser = "http://xmlns.oracle.com/communications/inventory/webservice/service";
declare namespace oms = "urn:com:metasolv:oms:xmlapi:1";

declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "xml";
declare option output:indent "yes";

declare function local:generateUpdate($uimResponse as element()*) as element()
{

    let $update := 
            <OrderDataUpdate xmlns="http://www.metasolv.com/OMS/OrderDataUpdate/2002/10/25">
                    <TetheringType>{ $uimResponse//characteristics[name='Tethering Type']/value/text() }</TetheringType>
            </OrderDataUpdate>
    return 
        $update     
};



let $uimResponse := fn:root(.)/soap:Envelope/soap:Body/ser:serviceLookUpResponse
let $mdn := $uimResponse//configurationItems[name = 'MDN']/resourceAssignment/resource/name/text()    
let $output := local:generateUpdate($uimResponse)   
return
    (
        $output

    )

If I modify the function local:generateUpdate to remove xmlns="http://www.metasolv.com/OMS/OrderDataUpdate/2002/10/25", then text content of TetheringType gets populated in the generated output xml which appears something like below:

<OrderDataUpdate>
<TetheringType>IE Tethering</TetheringType>
</Add>
</OrderDataUpdate>

What am I doing wrong? Can someone explain to me why is it that on adding xmlns=”http://www.metasolv.com/OMS/OrderDataUpdate/2002/10/25” to the OrderDataUpdate element, the text content of xml nodes are not populated in the xml output. I need the <OrderDataUpdate> to be associated with the namespace "http://www.metasolv.com/OMS/OrderDataUpdate/2002/10/25"

Any help would be appreciated.

Thanks in advance.

1 Answer 1

1

At first glance, it looks as though by declaring a default namespace on your OrderDataUpdate element, you have caused a change in the interpretation of the unprefixed names characteristics, name, and value which occur lexically within that element. Your TetheringType element gets no text content because the XPath is matching nothing (there are no characteristics element in the namespace http://www.metasolv.com/OMS/OrderDataUpdate/2002/10/25 in your input).

On second glance, this hypothesis is confirmed by the XPath spec and by the behavior of the XQuery processors I have checked with.

There are at least two simple ways to fix your problem. First, you could avoid the name capture by not declaring a default namespace:

declare function local:generateUpdate(  
  $uimResponse as element()*
) as element() {
  let $update := <odu:OrderDataUpdate 
                    xmlns:odu=
                    "http://www.metasolv.com/OMS/OrderDataUpdate/2002/10/25">
                   <odu:TetheringType>{ 
                     $uimResponse//characteristics[name='Tethering Type']
                     /value/text() 
                   }</odu:TetheringType>
                 </odu:OrderDataUpdate>
  return $update     
};

Or you could just move the calculation of the text out of the scope of the default namespace declaration:

declare function local:generateUpdate(
  $uimResponse as element()*
) as element() {
  let $tttext := $uimResponse
                     //characteristics[name='Tethering Type']
                     /value/text() 
  let $update := <OrderDataUpdate 
                   xmlns="http://www.metasolv.com/OMS/OrderDataUpdate/2002/10/25">
                    <TetheringType>{ 
                     $tttext
                   }</TetheringType>
                 </OrderDataUpdate>
  return $update     
};
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. It couldn't have been a more easier than that. The second approach of moving the calculation of the text out of the scope of the default namespace declaration worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.