Author |
Message
|
m.schneider |
Posted: Tue Jul 15, 2008 7:39 am Post subject: MA0T replace, overlay, delete XML-Elements |
|
|
Centurion
Joined: 10 Apr 2007 Posts: 132 Location: Germany
|
I planning to compare xml-messages, ...
load-->Put-->progress-->get-->compare with saved msg
Problem is that they have fields that are unique:
<msg>
<id>12345<id>
<timestam>12.07.08 14:15</timestam>
<a></a>
<b></b>
<c></c>
</msg>
Is there a way to replace, overlay, delete these values?
Thx |
|
Back to top |
|
 |
sami.stormrage |
Posted: Tue Jul 15, 2008 7:49 am Post subject: |
|
|
 Disciple
Joined: 25 Jun 2008 Posts: 186 Location: Bangalore/Singapore
|
Either I am not getting ur question or this might sound bit technically inacurate to some.. but theres a tool called XML compare to compare two XML messages easily.. is that ur requirement? _________________ *forgetting everything * |
|
Back to top |
|
 |
m.schneider |
Posted: Tue Jul 15, 2008 8:02 am Post subject: |
|
|
Centurion
Joined: 10 Apr 2007 Posts: 132 Location: Germany
|
The problem is that can't compare the progessed msg with the saved one, because each msg has a unique id and timestamp. Therefor I asked if it is possible to manipulate the unique fields. |
|
Back to top |
|
 |
JosephGramig |
Posted: Tue Jul 15, 2008 8:11 am Post subject: |
|
|
 Grand Master
Joined: 09 Feb 2006 Posts: 1244 Location: Gold Coast of Florida, USA
|
m.schneider wrote: |
Is there a way to replace, overlay, delete these values? |
Well, the SET statement can be used to "replace, overlay" the values and if you SET the value to NULL, the element in the msg tree will be deleted.
For what it is worth...  |
|
Back to top |
|
 |
m.schneider |
Posted: Tue Jul 15, 2008 8:29 am Post subject: |
|
|
Centurion
Joined: 10 Apr 2007 Posts: 132 Location: Germany
|
Is there a SET in MA0T? Do you have an example?
I didn't find anything in the documentation, ... |
|
Back to top |
|
 |
JosephGramig |
Posted: Tue Jul 15, 2008 8:43 am Post subject: |
|
|
 Grand Master
Joined: 09 Feb 2006 Posts: 1244 Location: Gold Coast of Florida, USA
|
No, I didn't know you were talking about MA0T.
I have used that tool, but not the way you are trying it... |
|
Back to top |
|
 |
JosephGramig |
Posted: Tue Jul 15, 2008 9:12 am Post subject: |
|
|
 Grand Master
Joined: 09 Feb 2006 Posts: 1244 Location: Gold Coast of Florida, USA
|
now that I stop and think about it, if you know the exact off set and number of bytes you want to overlay, you can overlay those values in the message (actually it will be in the buffer).
There is an overlay command/feature. |
|
Back to top |
|
 |
timjohnarm |
Posted: Tue Jul 15, 2008 12:54 pm Post subject: |
|
|
Apprentice
Joined: 28 Sep 2004 Posts: 40 Location: Melbourne Australia
|
You need to get V1.2.9 if you don't already have it. It lets you set up your compare files with regular expressions in them. In fact it uses the PCRE(Perl Compatible Regular Expressions) library so your regular expressions can be quite sophisticated.
For the example you have given your compare file would look like
<msg>
<id>12345<id>
<timestam>\d{2}\.\d{2}\.\d{2} \d{2}:\d{2}</timestam>
<a></a>
<b></b>
<c></c>
</msg>
If the <id> also varies then it would become
<msg>
<id>\d{5}<id>
<timestam>\d{2}\.\d{2}\.\d{2} \d{2}:\d{2}</timestam>
<a></a>
<b></b>
<c></c>
</msg>
And if you don't care about validating it as an actual timestamp then
<msg>
<id>12345<id>
<timestam>.{14}</timestam>
<a></a>
<b></b>
<c></c>
</msg>
I have found the best technique for building regular expressions to match really complex messages is to start from a match everything regex and cut and paste from a copy of the message to be matched. In this way if you get it wrong you'll know it was the bit you just added.
Thus working through your example the series of regular expressions might go like this.
^.*
^<msg>
<id>12345<id>
.*
^<msg>
<id>12345<id>
<timestam>.{14}</timestam>
.*
^<msg>
<id>12345<id>
<timestam>.{14}</timestam>
<a></a>
<b></b>
<c></c>
</msg>
$
Note in this example the use of the ^(caret) to anchor the overall regular expression.
Regards
Tim Armstrong |
|
Back to top |
|
 |
timjohnarm |
Posted: Tue Jul 15, 2008 1:14 pm Post subject: |
|
|
Apprentice
Joined: 28 Sep 2004 Posts: 40 Location: Melbourne Australia
|
Also to take sami's point a bit further you can invoke any external tool you like using the <System>command.
So in your script you could
<PutFile>
<File>SaveFile.txt</File>
<Dir>c:\SaveDir</Dir>
</PutFile>
<System>
<Command>c:\ProgramFiles\SpecialUtil.exe c:\SaveDir\SavedFile.txt c:\CompareDir>CompareFile.txt</Command>
</System>
<If Cond="%LastCC%.NE.0">
<StdOut>LastCC=%LastCC% LastRC=%LastRC%</StdOut>
-- Do something about it
<ExitTest/>
</If>
This of course assumes that SpecialUtil.exe returns a different ConditionCode depending on success or failure.
Also note that to avoid the test just failing you need and <If...> statement immediately after the MsgTest command that could fail.
Regards
Tim Armstrong |
|
Back to top |
|
 |
m.schneider |
Posted: Tue Jul 15, 2008 11:30 pm Post subject: |
|
|
Centurion
Joined: 10 Apr 2007 Posts: 132 Location: Germany
|
Thanks for your reply and examples.
I would prefer to keep it simple. So is there a way to delete the content of the <id> and <timestamp> tags wich can be variable in length. Perhaps get the position of the tags and overlay and delete the content, ...
This would make it easy to compare the msg with a saved msg. Intention of this is to automate regression testing for the message broker. |
|
Back to top |
|
 |
timjohnarm |
Posted: Thu Jul 17, 2008 12:29 pm Post subject: |
|
|
Apprentice
Joined: 28 Sep 2004 Posts: 40 Location: Melbourne Australia
|
Yes if you know the fixed position of the string you could overlay with a known value. But then you are going to get a whole lot of <Overlay> commands very quickly. The regular expression file is really the way to go, you capture a sample message put regular expressions in where the timestamps are and away you go, for something with only three or four variable elements it really is quite quick to do.
Here is the set I keep in a clipboard file for cutting and pasting.
\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}
\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{6}
\d{4}-\d{2}-\d{2}
\d{2}:\d{2}:\d{2}.\d{3}
Tim |
|
Back to top |
|
 |
timjohnarm |
Posted: Sun Jul 27, 2008 3:49 pm Post subject: |
|
|
Apprentice
Joined: 28 Sep 2004 Posts: 40 Location: Melbourne Australia
|
Now that I understand more about PCRE, V1.3.0 is on the way, it includes code to help locate the actual position in the buffer and the regular expression where a mismatch has occured. |
|
Back to top |
|
 |
|