XML File Transformations
Posted: Tue Feb 03, 2015 3:34 pm
Hi,
Being not very familiar with XML files, I am struggling a bit to achieve the following objective. It will be very helpful if someone can please direct me to right approach or design.
Objective: Read a XML file, apply some transformations to its data (e.g. switch cases, change some values, etc) and output it to another XML file with the same layout.
A sample record from the input file:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<import_data>
<so_product company="XYZ-US" part_number="81001074" category="Product Associations.Packaging" description="Ring,Crimp,1/2",Pkg/10 " >
<so_product_attribute name="Brand-XYZ" value="ABCDRD"/>
<so_product_attribute name="BrandName" value="ABCD Radiant"/>
<so_product_attribute name="Description-PriceGroup-XYZ" value="Onix/Hydro"/>
<so_product_attribute name="Description-ProductLine-XYZ" value="PEX Parts"/>
<so_product_attribute name="Description1-XYZ" value="Ring,Crimp,1/2",Pkg/10"/>
<so_product_attribute name="EANUCCType" value="UK"/>
<so_product_attribute name="EnvironmentalIdentifier" value="NO_ENVIRONMENTAL_ATTRIBUTE_SPECIFIED"/>
<so_product_attribute name="FinishedGood-XYZ" value="YES"/>
<so_product_attribute name="FunctionalName_en-US" value=""/>
<so_product_attribute name="GtinName_en-US" value=""/>
<so_product_attribute name="HazardousMaterialClassification" value="NO_MSDS_AND_NOT_REGULATED_BY_DOT_(CFR49)"/>
<so_product_attribute name="IsItemAvailableForDirectToConsumerDelivery" value="false"/>
<so_product_attribute name="IsItemAvailableForSpecialOrder" value="false"/>
<so_product_attribute name="IsItemSubjectToUSPatent" value="false"/>
<so_product_attribute name="IsNetContentDeclarationIndicated" value="false"/>
<so_product_attribute name="IsNonSoldTradeItemReturnable" value="false"/>
<so_product_attribute name="IsPackagingMarkedAsRecyclable" value="false"/>
<so_product_attribute name="IsPackagingMarkedReturnable" value="false"/>
<so_product_attribute name="IsSecurityTagPresent" value="false"/>
<so_product_attribute name="IsTradeItemABaseUnit" value="false"/>
<so_product_attribute name="IsTradeItemAConsumerUnit" value="false"/>
<so_product_attribute name="IsTradeItemADespatchUnit" value="true"/>
<so_product_attribute name="IsTradeItemAnInvoiceUnit" value="false"/>
<so_product_attribute name="IsTradeItemAnOrderableUnit" value="false"/>
<so_product_attribute name="IsTradeItemMarkedAsRecyclable" value="false"/>
<so_product_attribute name="IsTradeItemRecalled" value="false"/>
<so_product_attribute name="IsWoodAComponentOfThisItem" value="false"/>
<so_product_attribute name="ItemStatus-XYZ" value="AC"/>
<so_product_attribute name="ItemType-XYZ" value="cring"/>
<so_product_attribute name="Kit-Ferguson" value="N"/>
<so_product_attribute name="LegacyPartNumber-XYZ" value="PCCR3X-10"/>
<so_product_attribute name="ListPriceUnitOfMeasure" value="EACH CONSUMER UNIT"/>
<so_product_attribute name="LongDescription_en-US" value="ABCD Radiant "/>
<so_product_attribute name="ManufacturerName" value="ABCD"/>
<so_product_attribute name="MFGName" value="ABCD"/>
<so_product_attribute name="NSFLeadFreeListed" value="N"/>
<so_product_attribute name="NSFSafetyListing-XYZ" value="N"/>
<so_product_attribute name="OrderableUnitIndicator" value="EA"/>
<so_product_attribute name="OrderingLeadTimeUnit" value="DA"/>
<so_product_attribute name="OrderQuantityMinimum" value="1"/>
<so_product_attribute name="OrderQuantityMultiple" value="1"/>
<so_product_attribute name="PackageDepth-XYZ" value="5" unit_name="inch"/>
<so_product_attribute name="PackageGTIN-XYZ" value="20840213013657"/>
<so_product_attribute name="PackageHeight-XYZ" value="4" unit_name="inch"/>
<so_product_attribute name="PackageQtyPer-XYZ" value="10"/>
<so_product_attribute name="PackageWeight-XYZ" value="1.5" unit_name="pound"/>
<so_product_attribute name="PackageWidth-XYZ" value="5" unit_name="inch"/>
<so_product_attribute name="PiecesPerTradeItem" value="1"/>
<so_product_attribute name="PiecesPerTradeItemUnit" value="EA"/>
<so_product_attribute name="PIMComplete-XYZ" value="NO"/>
<so_product_attribute name="PriceGroup-XYZ" value="211"/>
<so_product_attribute name="PrimarySite-XYZ" value="A09"/>
<so_product_attribute name="PriorityCode-XYZ" value="C"/>
<so_product_attribute name="ProductLine-XYZ" value="K722"/>
<so_product_attribute name="ProductManager-XYZ" value="BARRETSR"/>
<so_product_attribute name="ProductTypeCode" value="CA"/>
<so_product_attribute name="PurMfg-XYZ" value="M"/>
<so_product_attribute name="ReturnGoodsPolicy" value="CALL_FOR_AUTHORIZATION"/>
<so_product_attribute name="StockStatus-XYZ" value="STK"/>
<so_product_attribute name="TargetAudience-XYZ" value="NS"/>
<so_product_attribute name="Unit of Measure" identifying="true" value="MASTER"/>
<product_association name="Packaging" company="XYZ-US" part_number="81001074" >
<product_association_attribute name="Quantity" value="10">
</product_association_attribute>
</product_association>
</so_product>
<import_data>
Thank you very much in advance.
Being not very familiar with XML files, I am struggling a bit to achieve the following objective. It will be very helpful if someone can please direct me to right approach or design.
Objective: Read a XML file, apply some transformations to its data (e.g. switch cases, change some values, etc) and output it to another XML file with the same layout.
A sample record from the input file:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<import_data>
<so_product company="XYZ-US" part_number="81001074" category="Product Associations.Packaging" description="Ring,Crimp,1/2",Pkg/10 " >
<so_product_attribute name="Brand-XYZ" value="ABCDRD"/>
<so_product_attribute name="BrandName" value="ABCD Radiant"/>
<so_product_attribute name="Description-PriceGroup-XYZ" value="Onix/Hydro"/>
<so_product_attribute name="Description-ProductLine-XYZ" value="PEX Parts"/>
<so_product_attribute name="Description1-XYZ" value="Ring,Crimp,1/2",Pkg/10"/>
<so_product_attribute name="EANUCCType" value="UK"/>
<so_product_attribute name="EnvironmentalIdentifier" value="NO_ENVIRONMENTAL_ATTRIBUTE_SPECIFIED"/>
<so_product_attribute name="FinishedGood-XYZ" value="YES"/>
<so_product_attribute name="FunctionalName_en-US" value=""/>
<so_product_attribute name="GtinName_en-US" value=""/>
<so_product_attribute name="HazardousMaterialClassification" value="NO_MSDS_AND_NOT_REGULATED_BY_DOT_(CFR49)"/>
<so_product_attribute name="IsItemAvailableForDirectToConsumerDelivery" value="false"/>
<so_product_attribute name="IsItemAvailableForSpecialOrder" value="false"/>
<so_product_attribute name="IsItemSubjectToUSPatent" value="false"/>
<so_product_attribute name="IsNetContentDeclarationIndicated" value="false"/>
<so_product_attribute name="IsNonSoldTradeItemReturnable" value="false"/>
<so_product_attribute name="IsPackagingMarkedAsRecyclable" value="false"/>
<so_product_attribute name="IsPackagingMarkedReturnable" value="false"/>
<so_product_attribute name="IsSecurityTagPresent" value="false"/>
<so_product_attribute name="IsTradeItemABaseUnit" value="false"/>
<so_product_attribute name="IsTradeItemAConsumerUnit" value="false"/>
<so_product_attribute name="IsTradeItemADespatchUnit" value="true"/>
<so_product_attribute name="IsTradeItemAnInvoiceUnit" value="false"/>
<so_product_attribute name="IsTradeItemAnOrderableUnit" value="false"/>
<so_product_attribute name="IsTradeItemMarkedAsRecyclable" value="false"/>
<so_product_attribute name="IsTradeItemRecalled" value="false"/>
<so_product_attribute name="IsWoodAComponentOfThisItem" value="false"/>
<so_product_attribute name="ItemStatus-XYZ" value="AC"/>
<so_product_attribute name="ItemType-XYZ" value="cring"/>
<so_product_attribute name="Kit-Ferguson" value="N"/>
<so_product_attribute name="LegacyPartNumber-XYZ" value="PCCR3X-10"/>
<so_product_attribute name="ListPriceUnitOfMeasure" value="EACH CONSUMER UNIT"/>
<so_product_attribute name="LongDescription_en-US" value="ABCD Radiant "/>
<so_product_attribute name="ManufacturerName" value="ABCD"/>
<so_product_attribute name="MFGName" value="ABCD"/>
<so_product_attribute name="NSFLeadFreeListed" value="N"/>
<so_product_attribute name="NSFSafetyListing-XYZ" value="N"/>
<so_product_attribute name="OrderableUnitIndicator" value="EA"/>
<so_product_attribute name="OrderingLeadTimeUnit" value="DA"/>
<so_product_attribute name="OrderQuantityMinimum" value="1"/>
<so_product_attribute name="OrderQuantityMultiple" value="1"/>
<so_product_attribute name="PackageDepth-XYZ" value="5" unit_name="inch"/>
<so_product_attribute name="PackageGTIN-XYZ" value="20840213013657"/>
<so_product_attribute name="PackageHeight-XYZ" value="4" unit_name="inch"/>
<so_product_attribute name="PackageQtyPer-XYZ" value="10"/>
<so_product_attribute name="PackageWeight-XYZ" value="1.5" unit_name="pound"/>
<so_product_attribute name="PackageWidth-XYZ" value="5" unit_name="inch"/>
<so_product_attribute name="PiecesPerTradeItem" value="1"/>
<so_product_attribute name="PiecesPerTradeItemUnit" value="EA"/>
<so_product_attribute name="PIMComplete-XYZ" value="NO"/>
<so_product_attribute name="PriceGroup-XYZ" value="211"/>
<so_product_attribute name="PrimarySite-XYZ" value="A09"/>
<so_product_attribute name="PriorityCode-XYZ" value="C"/>
<so_product_attribute name="ProductLine-XYZ" value="K722"/>
<so_product_attribute name="ProductManager-XYZ" value="BARRETSR"/>
<so_product_attribute name="ProductTypeCode" value="CA"/>
<so_product_attribute name="PurMfg-XYZ" value="M"/>
<so_product_attribute name="ReturnGoodsPolicy" value="CALL_FOR_AUTHORIZATION"/>
<so_product_attribute name="StockStatus-XYZ" value="STK"/>
<so_product_attribute name="TargetAudience-XYZ" value="NS"/>
<so_product_attribute name="Unit of Measure" identifying="true" value="MASTER"/>
<product_association name="Packaging" company="XYZ-US" part_number="81001074" >
<product_association_attribute name="Quantity" value="10">
</product_association_attribute>
</product_association>
</so_product>
<import_data>
Thank you very much in advance.