473,809 Members | 2,826 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlDocument


Hi Oleg and All,

Is this correct? Can I do this?

<code>

XmlDocument doc=new XmlDocument();
XPathNavigator nav = doc.CreateNavig ator();
//Load the xml file. Change path if needed
doc.Load(@"..\. .\..\books.xml" );
XslTransform xslt = new XslTransform();
xslt.Load(@"D:\ XML\XSL Ex2\Personnel2. xsl");
StringWriter fs = new StringWriter();
xslt.Transform( doc, null, fs, null);

XmlNode node=doc.Select SingleNode("boo kstore"); <-
Here is the problem
</code>

I need to transform the XML First using xslt.transform
then take the resulting XML and assign it to an XmlNode.
How should this be done?

Thanks,

JJBean :)

Nov 12 '05 #1
6 5704
JJ

I guess my question is worded wrong. This line :

XmlNode node=doc.Select SingleNode("boo kstore"); <- Here
is the problem

in my code. At this point does "doc" have the xslt
applied to it so that I am working with the resulting xml
in DOC?

JJ

-----Original Message-----

Hi Oleg and All,

Is this correct? Can I do this?

<code>

XmlDocument doc=new XmlDocument();
XPathNavigator nav = doc.CreateNavig ator();
//Load the xml file. Change path if needed
doc.Load(@"..\. .\..\books.xml" );
XslTransform xslt = new XslTransform();
xslt.Load(@"D:\ XML\XSL Ex2\Personnel2. xsl");
StringWriter fs = new StringWriter();
xslt.Transform( doc, null, fs, null);

XmlNode node=doc.Select SingleNode("boo kstore"); <-
Here is the problem
</code>

I need to transform the XML First using xslt.transform
then take the resulting XML and assign it to an XmlNode.How should this be done?

Thanks,

JJBean :)

.

Nov 12 '05 #2
JJ
This is really frustrating.

How do u apply a XSLT transform to an XmlDocument in c#?
Could you show me this in code ? I'm sure it's only
acouple of lines but can't find any examples on it.

Thanks,

JJ
-----Original Message-----

Hi Oleg and All,

Is this correct? Can I do this?

<code>

XmlDocument doc=new XmlDocument();
XPathNavigator nav = doc.CreateNavig ator();
//Load the xml file. Change path if needed
doc.Load(@"..\. .\..\books.xml" );
XslTransform xslt = new XslTransform();
xslt.Load(@"D:\ XML\XSL Ex2\Personnel2. xsl");
StringWriter fs = new StringWriter();
xslt.Transform( doc, null, fs, null);

XmlNode node=doc.Select SingleNode("boo kstore"); <-
Here is the problem
</code>

I need to transform the XML First using xslt.transform
then take the resulting XML and assign it to an XmlNode.How should this be done?

Thanks,

JJBean :)

.

Nov 12 '05 #3
JJ wrote:
I guess my question is worded wrong. This line :

XmlNode node=doc.Select SingleNode("boo kstore"); <- Here
is the problem

in my code. At this point does "doc" have the xslt
applied to it so that I am working with the resulting xml
in DOC?


Not really. XSLT never changes input XML. As per
xslt.Transform( doc, null, fs, null);
the result was written to fs.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #4
JJ wrote:
How do u apply a XSLT transform to an XmlDocument in c#?


Applying transformation doesn't mean modification of the input
XmlDocument. XmlDocument in your code is "source" XML in XSLT terms. The
result is never the same as source.
Actually I can imangine XSL transformation to be appended directly to
the input DOM, via XmlNodeWriter class:

XmlDocument doc = new XmlDocument();
doc.Load("input .xml");
XslTransform xslt = new XslTransform();
xslt.Load("test .xsl");
XmlNodeWriter nw = new XmlNodeWriter(d oc.DocumentElem ent, false);
xslt.Transform( doc, null, nw);
nw.Close();
doc.Save(Consol e.Out);

Above transformation appends result to the input DOM. Just tried, seems
to be working. Of course it could be dangerous, say you can replace
input data with result data prior they are processed.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #5
JJ
Hi Oleg,

I am interested in why you chose to use XmlNodeWriter
as the writer and not like Xmlwriter or streamwriter?

Thanks for helping me out Oleg, I really appreciate it!
And you have really wet my appetite on using XML. It's
pretty kool.
Thanks,
JJ
-----Original Message-----
JJ wrote:
How do u apply a XSLT transform to an XmlDocument in
c#?
Applying transformation doesn't mean modification of the inputXmlDocument. XmlDocument in your code is "source" XML in XSLT terms. Theresult is never the same as source.
Actually I can imangine XSL transformation to be appended directly tothe input DOM, via XmlNodeWriter class:

XmlDocument doc = new XmlDocument();
doc.Load("inpu t.xml");
XslTransform xslt = new XslTransform();
xslt.Load("tes t.xsl");
XmlNodeWrite r nw = new XmlNodeWriter (doc.DocumentEl ement, false);xslt.Transform (doc, null, nw);
nw.Close();
doc.Save(Conso le.Out);

Above transformation appends result to the input DOM. Just tried, seemsto be working. Of course it could be dangerous, say you can replaceinput data with result data prior they are processed.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

.

Nov 12 '05 #6
JJ wrote:
I am interested in why you chose to use XmlNodeWriter
as the writer and not like Xmlwriter or streamwriter?


Because I wanted to write to XmlDocument. And after all XmlNodeWriter is
XmlWriter. But when using StreamWriter, there is an superfluous overhead
of serializing and reparsing XML back to DOM. Using XmlNodeWriter you
can write directly to DOM with no any interim buffers.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #7

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

Similar topics

5
3615
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an instruction document (not data based) - same as using an xml web control. The resulting html is on the client? but what about the server side of things? Trying to figure out how to change and save the xmlDocument. It I put a button OUTSIDE of the...
1
17142
by: Martin Honnen | last post by:
With both .NET 1.0 and 1.1 I have found the following strange behaviour where System.Xml.XmlDocument.LoadXml doesn't throw an error when parsing a text node with a character reference to an invalid characters like &#x1;. Using the CreateTextNode method I create a text node containing "\u0001a" (C# string literal notation). As far as I understand the DOM allows that and an implementation is not required to throw an error. When OuterXml is...
4
4848
by: Robert Rossney | last post by:
I'm trying to send and receive XmlDocument objects using the System.Messaging.dll functions. The code I've written follows, as best I can tell, the methodology used in the sample code for the XmlMessageFormatter class. But it isn't working -- specifically, receiving isn't working. What am I doing wrong here? I begin by creating a MessageQueue object and setting up its XmlMessageFormatter to handle XmlDocument objects: System.Type...
2
6045
by: Graham Pengelly | last post by:
Hi I am trying to transform on System.Xml.XmlDocument into another using XslTransform without writing the object out to a file. I am guessing it should work something like this... public XmlDocument TransformXmlDoc(XmlDocument docToTransform, string xsltFilePath) { //load the xslt
2
6211
by: Dave | last post by:
Hi, Is there an easier way to pull a subset of nodes from one XmlDocument to another? I have the code below but would like to know if there is a more streamlined method. Thanks, Dave XmlNodeList nodeList = doc1.SelectNodes("//row"); foreach (XmlNode nodeCode in nodeList) { sb.Append(nodeCode.OuterXml);
8
6166
by: pete | last post by:
Hi there, Can someone explain to me why I can't bind to an XmlDocument but I can bind to an XmlNodeList. It's my understanding that they both implement the IEnumerable interface which is required for databinding. Am happy to work with the XmlNodeList but I can't shake the feeling I'm missing something <blush> Thanks, Pete
1
9699
by: Peter Nofelt | last post by:
Hey All, I'm running into this issue with parsing through an xml document by tag name. Below is an example xml document: File Name: things.xml <things> <people> <name>Peter</name>
1
1613
by: David | last post by:
I need to find a good online resource which teaches the use of the XmlDocument framework in more depth than is covered in MS's online doc. I need to create a multi-level XML document like the one listed below. Using XmlDocument, I can create the <books> and the individual <name> and <price> elements, but I am unsure how to create the <category> and <title> elements and close them after creating the detail elements. Eg. how can I go 2+...
5
10167
by: Rob Panosh | last post by:
Hello, I am trying to create a xmlDocument from as dataset. My code is listed below. All seems to go well until xmlDocument.Load(CType(ms, System.IO.Stream)) ... I keep getting the following error "The Root Element is Missing" ... any help would be appreciated. Thanks, Rob Panosh
2
13598
by: John Smith | last post by:
I'm writing webervice client using .Net 2.0. I have this class: public class MyWebService : SoapHttpClientProtocol { public XmlDocument validate(string url, XmlDocument xmlDocument) { this.Url = url;
0
9721
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
10633
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...
0
10376
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...
0
10114
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
9198
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
7651
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...
1
4331
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
3860
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
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.