473,378 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Tough transform to solve.........

Okay this is a slightly tricky one for us newbies, butI'm guessing
it'll be breeze for ou experts!

Problem:
You recieve a xml message which conforms to a common schema.
Everything is great and your clients (who send you their data based on
this agreed schema), do everything works as agreed and planned.
Over the next few months a few clients suddenly decide to add extra
nodes, therby breaking the schema validation. Then another client does
the same and adds their own nodes to the data. So now you have two
choices:

1. Stop accepting the broken xml.
2. Transform the broken xml into a schema conforming xml, by removing
the error nodes.

The only problem is you don't know what naughty error nodes can show
up at any time. However we know from the schema what nodes are good
and won't break the schema.
Eample:

In the following example how could I make sure only the <GOODNODES>
are kept and all the BADNODES are thrown away (remember there could be
man many BADNODES and to make things worse you just don't know what
they will be called).
In this example I have 2 bad nodes.

<?xml version="1.0" encoding="utf-16"?>
<CLIENTDATA xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ID="LONDON"
VERSION="1.2">
<HEADER>
<OPERATION NAME="PRICE">
<USERNAME>BOBSMITH</USERNAME>
<HOSTNAME>LONDON</HOSTNAME>
</OPERATION>
</HEADER>

<GOODNODE1>

<GOODNODE2 TYPE="MID" USEREDITED="false">

<GOODNODE3>
<CHILD1 TYPE="MID" USEREDITED="false">
<SWAP TYPE="MID" USEREDITED="false">19.16</SWAP>
</CHILD1>
</GOODNODE3>

<BADNODE1 TYPE="MID" USEREDITED="false">
<RUBBISH TYPE="RUBBISH1" USEREDITED="RUBBISH2">0000</RUBBISSH>
</BADNODE1>

<BADNODE2 TYPE="MID" USEREDITED="false">
<RUBBISH TYPE="RUBBISH1" USEREDITED="RUBBISH2">0000</RUBBISSH>
</BADNODE2>

<GOODNODE4>
<CHILD1 TYPE="MID" USEREDITED="false">
<SWAP TYPE="MID" USEREDITED="false">19.16</SWAP>
</CHILD1>
</GOODNODE4>
</GOODNODE2>
</GOODNODE1>

</CLIENTDATA>

The closest I could was to do something like this (close but I get
RUBBISH1RUBBISH2 etc embeded in the result):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/
>
<xsl:template match="@*|CLIENTDATA">
<xsl:copy>
<xsl:choose>
<xsl:when test="name()='CLIENTDATA' ">
<xsl:apply-templates select="@*|node()"/>
</xsl:when>
<xsl:otherwise>

</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>

<xsl:template match="@*|/CLIENTDATA/HEADER">
<xsl:copy>
<xsl:choose>
<xsl:when test="name()='HEADER' ">
<xsl:copy-of select="@*|/CLIENTDATA/HEADER"/>
</xsl:when>

<xsl:otherwise>

</xsl:otherwise>

</xsl:choose>
</xsl:copy>
</xsl:template>

<xsl:template match="text()|@*|/CLIENTDATA/GOODNODE1">
<xsl:copy>
<xsl:choose>
<xsl:when test="name()='GOODNODE1'">
<xsl:apply-templates select="@*|node()"/>
</xsl:when>

<xsl:otherwise>

</xsl:otherwise>

</xsl:choose>
</xsl:copy>
</xsl:template>

<xsl:template match="GOODNODE2">
<xsl:choose>
<xsl:when test="name()='GOODNODE2'">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>

<xsl:copy-of select="@*|/CLIENTDATA/GOODNODE1/GOODNODE2/
GOODNODE3"/>

<xsl:copy-of select="@*|/CLIENTDATA/GOODNODE1/GOODNODE2/
GOODNODE4"/>

</xsl:when>

<xsl:otherwise </xsl:otherwise>

</xsl:choose>

</xsl:template>
</xsl:stylesheet>

Is there a more correct and elegant way to do this??????
Thanks in advance
Ted.

Jun 14 '07 #1
2 1553
Te******@googlemail.com wrote:
Okay this is a slightly tricky one for us newbies, butI'm guessing
it'll be breeze for ou experts!

Problem:
You recieve a xml message which conforms to a common schema.
Everything is great and your clients (who send you their data based on
this agreed schema), do everything works as agreed and planned.
Over the next few months a few clients suddenly decide to add extra
nodes, therby breaking the schema validation. Then another client does
the same and adds their own nodes to the data. So now you have two
choices:

1. Stop accepting the broken xml.
Yes. Tell them their data is non-conformant and can't be processed.
If they want to add stuff, write them a new Schema. Bill them.

Sometimes you have to hit them with a lart until they comply.
2. Transform the broken xml into a schema conforming xml, by removing
the error nodes.
Nope.

///Peter
Jun 14 '07 #2
Peter Flynn wrote:
Te******@googlemail.com wrote:
>Okay this is a slightly tricky one for us newbies, butI'm guessing
it'll be breeze for ou experts!

Problem:
You recieve a xml message which conforms to a common schema.
Everything is great and your clients (who send you their data based
on this agreed schema), do everything works as agreed and planned.
Over the next few months a few clients suddenly decide to add extra
nodes, therby breaking the schema validation. Then another client
does the same and adds their own nodes to the data. So now you have
two choices:

1. Stop accepting the broken xml.

Yes. Tell them their data is non-conformant and can't be processed.
If they want to add stuff, write them a new Schema. Bill them.

Sometimes you have to hit them with a lart until they comply.
Agreed! :-D

The clients DO have access to the Schema, don't they?
They should be informed that your application is adhering _strictly_
to that Schema, and will reject anything that doesn't validate.

That's why the schema is there in the first place, and why _both_
parties have access to it.
>2. Transform the broken xml into a schema conforming xml, by removing
the error nodes.

Nope.
Never try to "understand" brokent files just to be helpful...
You will get a feature-creep that will overwhelm you.
Jun 14 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: eric rudolph | last post by:
1. I'm designing a PHP-based page that has a lot of design stuff in it. It's very tough to mix the HTML and PHP and have it be readable. The site isn't overall so complicated, there's just a lot of...
0
by: jajoo | last post by:
Hi to all of you, I hava a simply problem that could not solve. I am using javax.xml.Transform. I am trying to transform Documtne to xml file. I am setting...
0
by: Daniel Hirscher | last post by:
Hi, I like to transform a XML hierarchical tree structure into a HTML Table. All leaves are on the same depth of the tree. Every tree will give a correct table without empty cells. The number...
4
by: SC | last post by:
I couldn't write a program that make fourier transform in one and two dimens in C++. I couldn't solve correctly determinant of 3*3 matrix ic C++ too. Can you help me about that?? Thanks!
13
by: Elaine | last post by:
This has to do with self-joins and includes a running balance problem. Is it possible to do this using SQL alone? Amortization schedule -------------------------- Givens: beginning balance,...
0
by: KathyB | last post by:
Hi, I've been reading conflicting posts, etc., could someone please explain to me if msxml is used by asp.net to transform xml using an xsl stylesheet? If msxml is NOT used, CAN it be...i.e.,...
7
by: Dan | last post by:
I am trying to create a query (in either sql or the design view) to determine which two (or more I suppose if it's not too complicated) baseball players were teammates the longest. The database...
2
by: IdlePhaedrus | last post by:
Hi, I have a FFT routine that I converted from C++ to VB in a module as follows: Const M_PI = 3.1415926535897931 ' Fast Fourier Transform Public Sub FFT(ByRef rex() As Single, ByRef imx() As...
0
by: hyderabadblues | last post by:
Hi , I am trying to insert few elements of type midw_fi_tcl_AuxCtrlExt_MPItemDetail with integer as key in to a map using transform funtion, I am getting the following error transform(...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.