473,698 Members | 2,932 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML converter - "architectu ral" question

Hi everybody,

I have to build an application that translates documents from an A-XML
format to a B-XML format. The problems need a lot of elementary methods
translating an a-node to a b-node, so I thought to encapsule these
functions in some classes, using a sort of Command pattern.

Do you have any other suggestion about?

Thanks in advance,
Kind regards,
Giulio - Italia
Jun 20 '06 #1
6 1829
Would xslt suffice? You can use this with streams for maximum efficiency,
plus it is designed to do this job...

Marc
Jun 20 '06 #2
Marc Gravell ha scritto:
Would xslt suffice? You can use this with streams for maximum efficiency,
plus it is designed to do this job...


I know...
But I have to implement in a .NET dll something that was before implemented
using XSLT... so I cannot give the customer back the same thing he gave me! :-)

Anyway: we need s .NET dll because this "translator " must be used in a
complex scenario by some different applications.

Thanks,
Giulio
Jun 20 '06 #3
A .net dll doesn't preclude using xslt to do the work; quite the opposite,
as below; you can always pass in additional options with your xml to control
the output if you need. By using xslt you get to capitalise on the transform
functions, including indexing, Munchean grouping, pattern-matching etc. But
its your call.

I can't advise on the command-pattern usage, as it just isn't the way I
would have thought of doing it... back to the floor - any takers?

Marc

// load the xslt template as a string from a resx
XmlDocument sourceDoc = new XmlDocument();
sourceDoc.LoadX ml(TestProject. Properties.Reso urces.Transform );

// prepare a transform object
XslCompiledTran sform xsl = new XslCompiledTran sform();
xsl.Load(source Doc);

xsl.Transform(s ource, target);
Jun 20 '06 #4
Hi Marc,

Marc Gravell ha scritto:
A .net dll doesn't preclude using xslt to do the work;


But how can I log the "activity" of my application using xslt?

Thanks,
Giulio
Jun 21 '06 #5
Depends on what you mean by "activity"; if you mean individual runs of
the tranform (i.e. not the detail), then just log it in C# one side of
..Transform(); if you mean a blow-by-blow account of the steps you go
through, then I think (never tried) that you can use xsl:message (in
the xslt) to fire events back into C#; you catch them like:

XsltArgumentLis t args = new XsltArgumentLis t()
args.XsltMessag eEncountered += args_XsltMessag eEncountered; //
some handler; look at .Message

And use the overload on Transform() that accepts an XsltArgumentLis t

Marc

Jun 21 '06 #6
Working example:

using System;
using System.Xml;
using System.Diagnost ics;
using System.Windows. Forms;
using System.Xml.Xsl;
using System.IO;
public class Program {
static void Main() {
XmlDocument templateDoc = new XmlDocument();
templateDoc.Loa dXml(@"<?xml version=""1.0"" encoding=""UTF-8""
?>
<xsl:styleshe et version=""1.0""
xmlns:xsl=""htt p://www.w3.org/1999/XSL/Transform"">
<xsl:template match=""*"">
<xsl:message>Fo und <xsl:value-of select=""name() ""/></xsl:message>
<xsl:element name=""Freaked{ name()}"">
<xsl:apply-templates select=""*""/>
</xsl:element>
</xsl:template>
</xsl:stylesheet> ");

XslCompiledTran sform transform = new XslCompiledTran sform();
transform.Load( templateDoc);
XsltArgumentLis t args = new XsltArgumentLis t();
args.XsltMessag eEncountered +=new
XsltMessageEnco unteredEventHan dler(args_XsltM essageEncounter ed);

XmlDocument input = new XmlDocument();
input.LoadXml(" <Xml><Some><Dat a/><Data/></Some></Xml>");

using(MemoryStr eam stream = new MemoryStream()) {
transform.Trans form(input, args, stream);

Debug.WriteLine (transform.Outp utSettings.Enco ding.GetString( stream.ToArray( )));
}
}

static void args_XsltMessag eEncountered(ob ject sender,
XsltMessageEnco unteredEventArg s e) {
Debug.WriteLine (e.Message);
}
}

Jun 21 '06 #7

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

Similar topics

4
12448
by: Luca T. | last post by:
Hello, i need a way to find the home folder of the current user no matter if i am in Linux or Windows for instance: * Linux: /home/username * Windows: C:\Documents and Settings\username Is there any general way to do this?
4
5292
by: John Benson | last post by:
Hi, I'm using Tkinter and would like to know how to replace the red "Tk" logo in the left corner of the title bar of the root window with some other icon. Another question for curiosity's sake: I've often seen Tkinter referred to as the "standard" Python GUI. I assume that this is because it may be the oldest and perhaps the most cross-platform. Is that all that can be said for it? I've already heard about the Tkinter interpretive...
4
1787
by: Amir Michail | last post by:
Hi, We are planning to have "lecture preparation" discussions in comp3141 at UNSW, where anyone can participate -- not only students taking the subject. There is a heavy python component in this class and I was wondering whether anyone is interested in participating in these discussions. We are looking for both python beginners and experts.
36
6383
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but something I'll need in this case is some experience-based set of rules about how to use python in this context. For example... is defining readonly attributes in classes worth the hassle ? Does duck-typing scale well in complex
9
5807
by: Peter Hansen | last post by:
The term "mock filesystem" refers to code allowing unit or acceptance tests to create, read and write, and manipulate in other ways "virtual" files, without any actual disk access. Everything is held in memory and therefore fast, without risk of damaging real files, and with none of the messiness of leftover files after testing. Googling the archives and the web suggests that only I and Remy Blank have done much along these lines. I...
35
2939
by: les_ander | last post by:
Hi, I know that i can do readline() from a file object. However, how can I read till a specific seperator? for exmple, if my files are name profession id #
6
2638
by: Todd_Calhoun | last post by:
I'm trying to learn Python (and programming), and I'm wondering if there are any places where I can find small, simple programs to study. Thanks.
4
6871
by: VMI | last post by:
How can I create a comboBox that will display the first item that begins with the group of letters I type? In my current combobox (it's a DropDownList), if I press the letters "S" and "A" consecutively, it'll display the first item that starts with "S" and then the first item that begins with "A". What can I do so that if I type those two letters, iit'll display the first item that starts with "SA". And if I then press "T", it'll display...
10
2021
by: Luke Meyers | last post by:
So, just a little while ago I had this flash of insight. It occurred to me that, while of course in general there are very good reasons for the conventional two-file header/implementation separation for each C++ class, there are cases in which this paradigm contributes nothing and simply introduces extra boilerplate overhead. The particular case I have in mind is CppUnit tests. Each test header is only ever included by the...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8904
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7741
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4624
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.