473,748 Members | 10,058 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 1835
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
12454
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
5293
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
1789
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
6394
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
5812
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
2950
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
2639
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
6876
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
2024
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
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9312
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
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
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...
1
3300
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
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
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.