XML spliting

hi,
Am able to split an XML file by using follwing awk command,

awk 'NR==1{x=$0;next}/<\/Order>/{print y RS $0 RS "</Order>">f}/Order BillToKey/{f="file"++n".xml";y=x}{y=y RS $0}' filename.xml

but i need to insert a following tag in the begining of every file how to do so. The tag is as follows

<PIXOrder version="1.0" timestamp="2010-08-24T23:00:40">
awk 'NR==1{x=$0;next; print "<PIXOrder version=\"1.0\" timestamp=\"2010-08-24T23:00:40\">">f}/<\/Order>/{print y RS $0 RS  "</Order>">>f}/Order BillToKey/{f="file"++n".xml";y=x}{y=y RS  $0}' filename.xml

?

Hi,
Thanks for tha fast reply. the tag is located at the top of the source xml,so i want to read it dynamically and place in all the splited xml files.

Please post an example of your input file and expected output files

hi,
My xml will be in the following format... with multiple Orders, each order will split into a different xml file.I want the very first tag i,e
<PIXOrder version="1.0" timestamp="2010-08-24T23:00:40"> should be in every xml file reading it dynamically.

<PIXOrder version="1.0" timestamp="2010-08-24T23:00:40">
<Order BillToKey="20100806104040685337" Createts="2010-08-06T10:56:57-06:00" Createuserid="CreateGuestOrder" 
CustomerEMailID="jithesh.p@target.com" DocumentType="0001" DraftOrderFlag="N" EnterpriseCode="Target.com"
EntryType="10" MaxOrderStatus="1100" MaxOrderStatusDesc="Created" MinOrderStatus="1100"
MinOrderStatusDesc="Created" Modifyts="2010-08-06T10:57:53-06:00" Modifyuserid="InternalOrderValidationTaskAgent"
MultipleStatusesExist="N" OrderComplete="N" OrderDate="2010-08-06T04:56:55-06:00" OrderHeaderKey="20100806105655686045"
OrderNo="1046001" OrderType="EVEREST" PaymentStatus="AWAIT_AUTH" ReturnByGiftRecipient="" SaleVoided="N"
SellerOrganizationCode="Target.com" Status="Created" TaxExemptFlag="N" TaxExemptionCertificate="" TaxJurisdiction=""
TaxPayerId="" TermsCode="" TotalAdjustmentAmount="0.00" isHistory="N">
<Extn ExtnBrowserTimeZone="EST"
ExtnHttpHost="httpHost" ExtnIPAddress="10.10.2.3" ExtnMemberCookieFlag="N" ExtnSessionTime="22746646" /> 
<PriceInfo Currency="USD" /> 
<OrderLines TotalNumberOfRecords="2">
<OrderLine CarrierServiceCode="G2" DeliveryMethod="SHP" FulfillmentType="ShipToHome" GiftFlag="N"
IsBundleParent="N" ItemGroupCode="PROD" KitCode="" LevelOfService="G2" LineType="" MaxLineStatus="1100"
MaxLineStatusDesc="Created" MinLineStatus="1100" MinLineStatusDesc="Created" MultipleStatusesExist="N"
OpenQty="1.00" OrderHeaderKey="20100806105655686045" OrderLineKey="20100806105655686047" OrderedQty="1.00"
OriginalOrderedQty="1.00" PackListType="" PrimeLineNo="1" Purpose="" ReturnReason="" ScacAndService="" ScacAndServiceKey=""
ShipToKey="20100806104040685341" Status="Created" SubLineNo="1" isHistory="N">
<Extn ExtnIsPreOrder="N" /> 
</Order>

A side note. The output documents you wish to create, i.e.

<PIXOrder version="1.0" timestamp="2010-08-24T23:00:40">
<Order BillToKey="20100806104040685337" Createts="2010-08-06T10:56:57-06:00" Createuserid="CreateGuestOrder" CustomerEMailID="jithesh.p@target.com" DocumentType="0001" DraftOrderFlag="N" EnterpriseCode="Target.com" EntryType="10" MaxOrderStatus="1100" MaxOrderStatusDesc="Created" MinOrderStatus="1100" MinOrderStatusDesc="Created" Modifyts="2010-08-06T10:57:53-06:00" Modifyuserid="InternalOrderValidationTaskAgent" MultipleStatusesExist="N" OrderComplete="N" OrderDate="2010-08-06T04:56:55-06:00" OrderHeaderKey="20100806105655686045" OrderNo="1046001" OrderType="EVEREST" PaymentStatus="AWAIT_AUTH" ReturnByGiftRecipient="" SaleVoided="N" SellerOrganizationCode="Target.com" Status="Created" TaxExemptFlag="N" TaxExemptionCertificate="" TaxJurisdiction="" TaxPayerId="" TermsCode="" TotalAdjustmentAmount="0.00" isHistory="N">
.....
</Order>

will be neither well-formed or valid XML documents.

hi,
Since am a very new to XMl,May i know why it wouldnt be a valid XML document? what would be the reason.

The concepts of wellformness and valid in XML documents are simple enough.

See this tutorial: Creating a Well-Formed XML Document.