Joseph DeVore's Blog: Regular Expressions


Viewing By Category : Regular Expressions / Main
February 24, 2007
Since my brain is consumed with Flex, Flash, ActionScript 2 and 3, ASP (Classic VB Script stylee boyee!!) and ColdFusion 8 lately - I figured I'd blog about this regular expression in case I for some reason forget regular expressions or need to point someone to this code snippet...

<!--- some XML input with no data, just a bunch of closed nodes --->

<cfsavecontent variable="xml">
<RatingServiceSelectionResponse>
   <Response>
      <ResponseStatusCode/>
      <ResponseStatusDescription/>
   </Response>
   <RatedShipment>
      <Service>
         <Code/>
      </Service>
      <RatedShipmentWarning/>
      <BillingWeight>
         <UnitOfMeasurement>
            <Code/>
            <Description/>
         </UnitOfMeasurement>
         <Weight/>
      </BillingWeight>
      <TransportationCharges>
         <CurrencyCode/>
         <MonetaryValue/>
      </TransportationCharges>
      <ServiceOptionsCharges>
         <CurrencyCode/>
         <MonetaryValue/>
      </ServiceOptionsCharges>
      <TotalCharges>
         <CurrencyCode/>
         <MonetaryValue/>
      </TotalCharges>
      <GuaranteedDaysToDelivery/>
      <ScheduledDeliveryTime/>
      <RatedPackage>
         <TransportationCharges>
            <CurrencyCode/>
            <MonetaryValue/>
         </TransportationCharges>
         <ServiceOptionsCharges>
            <CurrencyCode/>
            <MonetaryValue/>
         </ServiceOptionsCharges>
         <TotalCharges>
            <CurrencyCode/>
            <MonetaryValue/>
         </TotalCharges>
         <Weight/>
         <BillingWeight>
            <UnitOfMeasurement>
               <Code/>
               <Description/>
            </UnitOfMeasurement>
            <Weight/>
         </BillingWeight>
      </RatedPackage>
   </RatedShipment>
</RatingServiceSelectionResponse>
</cfsavecontent>

<cfscript>
// regular expression to find shorthand nodes
re='<([^\/>]*)/>';
   
// replace with tag pair
xml=reReplace(xml,re,'<\1></\1>','all');
   
// write formatted HTMl code to screen
writeOutput(htmlCodeFormat(xml));
</cfscript>

Comments

Comments are not allowed for this entry.













Editor Login ›