You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "DePaul, James" <ja...@xcelenergy.com> on 2002/09/23 22:49:05 UTC

Removing Parent Elements...

Can someone recommend a solution to the following problem:

We are given a data structure (as shown below) and we need to 'transform' it into another retulting structure.  Here is the input XML:

<?xml version="1.0" encoding="UTF-8"?>
<OperationResult>
	<Data>
		<AreaLightingMaintenance>
			<Async>
				<uploadEnrolments>
					<v1.0>
						<Result>
							<OutputFileName>Text</OutputFileName>
							<ExceptionFileName>Text</ExceptionFileName>
							<CustomerResultFileName>Text</CustomerResultFileName>
							<PremiseResultFileName>Text</PremiseResultFileName>
							<PostalAddressResultFileName>Text</PostalAddressResultFileName>
							<ServiceResultFileName>Text</ServiceResultFileName>
							<CustomerExceptionReportFileName>Text</CustomerExceptionReportFileName>
							<PremiseExceptionReportFileName>Text</PremiseExceptionReportFileName>
							<PostalAddressExceptionReportFileName>Text</PostalAddressExceptionReportFileName>
							<ServiceExceptionReportFileName>Text</ServiceExceptionReportFileName>
							<PostalAddressFileName>Text</PostalAddressFileName>
							<PremiseOutputFileName>Text</PremiseOutputFileName>
							<ServiceOrderExceptionFileName>Text</ServiceOrderExceptionFileName>
							<MeterReadingsExceptionFileName>Text</MeterReadingsExceptionFileName>
							<StatusFileName>Text</StatusFileName>
							<AcknowledgementFileName>Text</AcknowledgementFileName>
						</Result>
					</v1.0>
				</uploadEnrolments>
			</Async>
		</AreaLightingMaintenance>
	</Data>
</OperationResult>


The final structure that we need to achieve at appears as follows:

<?xml version="1.0" encoding="UTF-8"?>
<OperationResult>
	<Data>
		<Result>
			<OutputFileName>Text</OutputFileName>
			<ExceptionFileName>Text</ExceptionFileName>
			<CustomerResultFileName>Text</CustomerResultFileName>
			<PremiseResultFileName>Text</PremiseResultFileName>
			<PostalAddressResultFileName>Text</PostalAddressResultFileName>
			<ServiceResultFileName>Text</ServiceResultFileName>
			<CustomerExceptionReportFileName>Text</CustomerExceptionReportFileName>
			<PremiseExceptionReportFileName>Text</PremiseExceptionReportFileName>
			<PostalAddressExceptionReportFileName>Text</PostalAddressExceptionReportFileName>
			<ServiceExceptionReportFileName>Text</ServiceExceptionReportFileName>
			<PostalAddressFileName>Text</PostalAddressFileName>
			<PremiseOutputFileName>Text</PremiseOutputFileName>
			<ServiceOrderExceptionFileName>Text</ServiceOrderExceptionFileName>
			<MeterReadingsExceptionFileName>Text</MeterReadingsExceptionFileName>
			<StatusFileName>Text</StatusFileName>
			<AcknowledgementFileName>Text</AcknowledgementFileName>
		</Result>
	</Data>
</OperationResult>

So we are essentially looking to position on the <Result> tag and delete the four immediate Parent Nodes (<AreaLightingMaintenance>, <Async>, <uploadEnrolments>, and <v1.0> - respectively).

Is there a code sample for fining a specific Child Node and working backwards to delete some of its Parent Elements?!  Or maybe there is yet another solution that someone could recommend?!

Thanks,
James




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Removing Parent Elements...

Posted by Siarhei Biarozkin <sb...@zandar.com>.
One way to do it is to apply an identity transform to your instance :

<xsl:template match="@*|node()">
   <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
   </xsl:copy>
 </xsl:template>

<!-- ignore these elements -->
<xsl:template match="AreaLightingMaintenance | Async
                                 | uploadEnrolments | v1.0">
   <xsl:apply-templates/>
 </xsl:template>

or , if you know for sure, the <Result> is all you'll ever need :

<xsl:template match="Data/*[not(self::Result)]">
   <xsl:apply-templates/>
 </xsl:template>

You'll not use Xerces explicitly if you go this route
Regards
Sergey Beryozkin
----- Original Message -----
From: "DePaul, James" <ja...@xcelenergy.com>
To: <xe...@xml.apache.org>
Sent: Monday, September 23, 2002 9:49 PM
Subject: Removing Parent Elements...


Can someone recommend a solution to the following problem:

We are given a data structure (as shown below) and we need to 'transform' it
into another retulting structure.  Here is the input XML:

<?xml version="1.0" encoding="UTF-8"?>
<OperationResult>
<Data>
<AreaLightingMaintenance>
<Async>
<uploadEnrolments>
<v1.0>
<Result>
<OutputFileName>Text</OutputFileName>
<ExceptionFileName>Text</ExceptionFileName>
<CustomerResultFileName>Text</CustomerResultFileName>
<PremiseResultFileName>Text</PremiseResultFileName>
<PostalAddressResultFileName>Text</PostalAddressResultFileName>
<ServiceResultFileName>Text</ServiceResultFileName>
<CustomerExceptionReportFileName>Text</CustomerExceptionReportFileName>
<PremiseExceptionReportFileName>Text</PremiseExceptionReportFileName>
<PostalAddressExceptionReportFileName>Text</PostalAddressExceptionReportFile
Name>
<ServiceExceptionReportFileName>Text</ServiceExceptionReportFileName>
<PostalAddressFileName>Text</PostalAddressFileName>
<PremiseOutputFileName>Text</PremiseOutputFileName>
<ServiceOrderExceptionFileName>Text</ServiceOrderExceptionFileName>
<MeterReadingsExceptionFileName>Text</MeterReadingsExceptionFileName>
<StatusFileName>Text</StatusFileName>
<AcknowledgementFileName>Text</AcknowledgementFileName>
</Result>
</v1.0>
</uploadEnrolments>
</Async>
</AreaLightingMaintenance>
</Data>
</OperationResult>


The final structure that we need to achieve at appears as follows:

<?xml version="1.0" encoding="UTF-8"?>
<OperationResult>
<Data>
<Result>
<OutputFileName>Text</OutputFileName>
<ExceptionFileName>Text</ExceptionFileName>
<CustomerResultFileName>Text</CustomerResultFileName>
<PremiseResultFileName>Text</PremiseResultFileName>
<PostalAddressResultFileName>Text</PostalAddressResultFileName>
<ServiceResultFileName>Text</ServiceResultFileName>
<CustomerExceptionReportFileName>Text</CustomerExceptionReportFileName>
<PremiseExceptionReportFileName>Text</PremiseExceptionReportFileName>
<PostalAddressExceptionReportFileName>Text</PostalAddressExceptionReportFile
Name>
<ServiceExceptionReportFileName>Text</ServiceExceptionReportFileName>
<PostalAddressFileName>Text</PostalAddressFileName>
<PremiseOutputFileName>Text</PremiseOutputFileName>
<ServiceOrderExceptionFileName>Text</ServiceOrderExceptionFileName>
<MeterReadingsExceptionFileName>Text</MeterReadingsExceptionFileName>
<StatusFileName>Text</StatusFileName>
<AcknowledgementFileName>Text</AcknowledgementFileName>
</Result>
</Data>
</OperationResult>

So we are essentially looking to position on the <Result> tag and delete the
four immediate Parent Nodes (<AreaLightingMaintenance>, <Async>,
<uploadEnrolments>, and <v1.0> - respectively).

Is there a code sample for fining a specific Child Node and working
backwards to delete some of its Parent Elements?!  Or maybe there is yet
another solution that someone could recommend?!

Thanks,
James




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Removing Parent Elements...

Posted by Joseph Kesselman <ke...@us.ibm.com>.
You can't "delete" nodes in the DOM. You can only remove them from the 
tree. Doing so removes their entire subtree.

The usual solution is to remove them, and move the descendent nodes you 
want to keep into the position these ancestors were removed from. (Insert 
before what used to be the removed ancestor's next-sibling.)

______________________________________
Joe Kesselman  / IBM Research

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org