|
Yes:
#include <comdef.h>
#import <msxml4.dll> // I am using version 4. You might have something else installed
...
using MSXML2::IXMLDOMDocument2Ptr;
using MSXML2::DOMDocument40;
...
CoInitialize(NULL);
IXMLDOMDocument2Ptr pXMLDom;
HRESULT hr = pXMLDom.CreateInstance(__uuidof(DOMDocument40));
if (FAILED(hr))
{
...
}
...
pXMLDom.Release();
CoUninitialize();
|
|
|
|
|
I need to export xml data to excel.This should be done using servlets.Somebody help me .
vidya
|
|
|
|
|
Hello, i would like to know how to sort an xml file. here is the xml file i have:
<books>
<book>
<title>Advanced XML
<publisher>Lucerne Publishing
<book>
<title>Learn XML Today
<publisher>MSPress
<book>
<title>XML for Gurus
<publisher>Lucerne Publishing
<book>
<title>Developing XML solutions
<publisher>MSPress
I don't have any template or style file.
I want to display a sorted information inside a listbox using C#:
Advanced XML, Lucerne Publishing
XML for Gurus, Lucerne Publishing
Developing XML solutions, MSPress
Learn XML Today, MSPress
I assume that we want to sort by the publisher first and then by the title.
Any suggestion will be great.
|
|
|
|
|
Sorry it didn't show the tags
<?xml version='1.0'?>
<Books>
<Book>
<Title>Advanced XML</Title>
<Publisher>Lucerne Publishing</Publisher>
</Book>
<Book>
<Title>Learn XML Today</Title>
<Publisher>MSPress</Publisher>
</Book>
<Book>
<Title>XML for Gurus</Title>
<Publisher>Lucerne Publishing</Publisher>
</Book>
<Book>
<Title>Developing XML solutions</Title>
<Publisher>MSPress</Publisher>
</Book>
</Books>
|
|
|
|
|
I did this in a hurry. The XSLT coding sample seems more complicated since I used strings for the xml and xslt.
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
namespace SortXml
{
class Program
{
static void Main(string[] args)
{
string xml =
"<?xml version='1.0'?>" +
"<Books>" +
"<Book>" +
"<Title>Advanced XML</Title>" +
"<Publisher>Lucerne Publishing</Publisher>" +
"</Book>" +
"<Book>" +
"<Title>Learn XML Today</Title>" +
"<Publisher>MSPress</Publisher>" +
"</Book>" +
"<Book>" +
"<Title>XML for Gurus</Title>" +
"<Publisher>Lucerne Publishing</Publisher>" +
"</Book>" +
"<Book>" +
"<Title>Developing XML solutions</Title>" +
"<Publisher>MSPress</Publisher>" +
"</Book>" +
"</Books>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlNodeList nodes =
doc.DocumentElement.SelectNodes(
"/Books/Book/Title/child::text()");
// Sorting using an array.
if (nodes.Count > 0)
{
string[] titles = new string[nodes.Count];
int i = 0;
foreach (XmlNode node in nodes)
{
titles[i++] = node.Value;
}
Array.Sort(titles);
foreach (string title in titles)
{
Console.WriteLine(title);
}
}
Console.WriteLine();
// Sorting using XSLT
string xslt =
"<xsl:stylesheet version='1.0' " +
"xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>" +
"<xsl:template match='/ | @* | node()'>" +
"<xsl:copy>" +
"<xsl:apply-templates select='@* | node()'>" +
"<xsl:sort select='Title'/>" +
"</xsl:apply-templates>" +
"</xsl:copy>" +
"</xsl:template>" +
"</xsl:stylesheet>";
XslCompiledTransform xct = new XslCompiledTransform();
StringReader strXslStr = new StringReader(xslt);
XmlReader rdrXsl = XmlReader.Create(strXslStr);
xct.Load(rdrXsl);
rdrXsl.Close();
strXslStr.Close();
XPathNavigator xpnav = doc.CreateNavigator();
StringBuilder sbXml = new StringBuilder();
XmlWriter sortedXml = XmlWriter.Create(sbXml);
xct.Transform(xpnav, sortedXml);
doc.LoadXml(sbXml.ToString());
sortedXml.Close();
nodes = doc.DocumentElement.SelectNodes(
"/Books/Book/Title/child::text()");
if (nodes.Count > 0)
{
foreach (XmlNode node in nodes)
{
Console.WriteLine(node.Value);
}
}
}
}
}
-- modified at 23:47 Tuesday 16th May, 2006
|
|
|
|
|
Hi George,
is XSLT a separate file or a new C# class.
I was wondering how can we create a XSL or XSLT file from an XML?
Sorry Im new to XML programming.
Donkaiser
|
|
|
|
|
XSTL (XSL) source code is really a XML (text) file:
<?xml version='1.0'?>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match='/ | @* | node()'>
<xsl:copy>
<xsl:apply-templates select='@* | node()'>
<xsl:sort select='Title'/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
The elements with the "xsl" namespace are used to manipulate, sort, and filter XML data. C# (my example uses the .Net 2.0 Framework) has classes that can compile and run XSLT source code to process XML data.
Go to http://www.w3.org/Style/XSL/[^] for more information. Also, search your Visual Studio Documentation on how to use it with C#.
-- modified at 10:34 Wednesday 17th May, 2006
|
|
|
|
|
Thank George,
I know how to create a xsl now. but how can we bind it to the existing xml file?
Donkaiser
|
|
|
|
|
I am assuming you are using C# 2.0. My example above shows you how. Anyway, I will make a commented snippet:
// Sorting using XSLT
string xslt =
"<xsl:stylesheet version='1.0' " +
"xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>" +
"<xsl:template match='/ | @* | node()'>" +
"<xsl:copy>" +
"<xsl:apply-templates select='@* | node()'>" +
"<xsl:sort select='Title'/>" +
"</xsl:apply-templates>" +
"</xsl:copy>" +
"</xsl:template>" +
"</xsl:stylesheet>";
XslCompiledTransform xct = new XslCompiledTransform(); // The XSLT Compiler/Transformer
StringReader strXslStr = new StringReader(xslt); // Create a XmlReader stream using a string source (the string = XSLT)
XmlReader rdrXsl = XmlReader.Create(strXslStr);
xct.Load(rdrXsl); // the XSLT Transformer reads the XSLT and compiles it.
rdrXsl.Close(); // Closing Streams
strXslStr.Close();
XPathNavigator xpnav = doc.CreateNavigator(); // Create the XPathNavigator from a XmlDocument Object
StringBuilder sbXml = new StringBuilder(); // Create a XmlWriter stream with a StringBuilder output buffer
XmlWriter sortedXml = XmlWriter.Create(sbXml);
xct.Transform(xpnav, sortedXml); // The actual transformation of the XML using the above XSLT document
doc.LoadXml(sbXml.ToString()); // The Transformed XML output is in the StringBuilder object.
sortedXml.Close(); // Close the stream.
|
|
|
|
|
Sroun Ngo wrote: Any suggestion will be great.
ok, then....
Sroun Ngo wrote: I assume
Don't make assumptions.
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
Hi All,
Could any one please provide me with the sample or example code for updating the data of XML files to MS Access database tables.?, Actually i need to make a vc++ dll which can read all xml files in a particular directory and update the data to coresponding table in MS Access database, I couldn't find any useful information on INTERNET or any articles for the same, if somebody have programmed a code for such a functionality, please help vc++ guru's!!..Thanks in Advance.!
Regards,
princenrj23
____________
|
|
|
|
|
nrj23 wrote: I couldn't find any useful information on INTERNET or any articles for the same
You are not likely to find code or an article providing you with a complete solution. However if you recursively break the overall problem domain down to it's constituent parts you will find samples and details of those smaller problems.
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
Dude what i am confused with is, how to open all xml files one by one from a single directory, parse the file and how do i know which element is to be updated to which column of which table(MS-Access Database)??, i am newbee to xml and vc++???, what is surprising to me is that there is no single tutorial or example code for this on internet?? dude if you have done such a programming in past plz post something useful?. It will be a great help...Thanks in Advance!!
|
|
|
|
|
There is nothing new in your second post. Please go back and read mine again. If there is anything in my post that you don't understand please tell me, specifically, and I will try to clarify it.
nrj23 wrote: dude if you have done such a programming in past plz post something useful?
I will be glad to help you with specific questions about a small parts of your code, one at a time, that you have a question about. So far I see no code from you.
I am not going to write your program for you and post it so you can copy and paste it into your solution. If you think that is how programming works you are headed in the wrong direction already.
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
I agree with led mike. You have several issues here without any example code displayed.
Nevertheless, I am assuming you are using native C++ and not Managed C++ or C++/CLI. Thus,search using "MSXML C++" at http://www.google.com/microsoft to find basic information on how to use the MSXML COM object. You will need to learn how to parse an XML document to obtain the data to place in the Access database (the table's columns should correspond with the XML document's element or attribute names).
Also, you may need to know how to update an Access database via native C++ code. You might want to search on the above site using 'OLEDB C++". There are some ATL OLEDB attributes that will make your programming efforts easier.
So, come back later and ask some specific questions. If they are more C++ related, you might get better results posting in the C++ forum.
|
|
|
|
|
Hi,
I tried to read XML data from a string. Suppose that I get a string like this:
<root><node1>567</node1><node2>Andbf</node2></root>.
I want to get the data contained within the xml elements. A little help can be useful. Thanks
Do your best to be the best
|
|
|
|
|
assign the string to a xmldocument and u can pass thro the nodes easily
eg:
string s= // your xmlstring here
XmlDocument doc = new XmlDocument();
doc.innerXml = s;
sathy
|
|
|
|
|
This works:
XmlDocument doc = new XmlDocument();
doc.LoadXml("<item><name>wrench</name></item>");
-- modified at 8:34 Tuesday 16th May, 2006
|
|
|
|
|
How do you save data from a form in C# to XML?
Illegal Operation
Making Computer Software Talk
|
|
|
|
|
System.Xml.XmlDocument.Save( string filePath)
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
|
I have an xsd (One of the elements in it is defined by an xs:enumeration). This xsd will change from time to time. So, my code should work even when the xsd changes.
My Tasks (on a winform):
1. Build a dataset from xsd (easily achieved ds.ReadXmlSchema("sample.xsd"))
2. Bind a datagrid to this dataset (dataGrid1.DataSource = ds.Tables[0])
3. Display a combobox in the column (which defined by an enum in the xsd) and display the enum values in the combo box(Problem)
I am looping through the columns of the datatable and trying to figure out if it was defined by an xs:enumeration in the xsd. During runtime, I can see that ds.Tables[0].Columns[2].SimpleType.enumeration contains the list of enumerator values. But, I am unable to figure out how to get to it during design time.
It would really if someone could tell me how to determine if a datacolumn is supposed to be taking only enumeration values provided in the xsd, and how to get access to these values so I can bind them to a combobox
I really appreciate the time you took to reply to this post!
Extract from a Sample XSD defining three columns:
<my:element name="ID" type="xs:decimal" minOccurs="0"/>
<my:element name="StartDate" type="xs:date" default="1990-01-01" minOccurs="0"/>
<my:element name="Employee">
<my:simpleType id="EmployeeName">
<my:restriction base="xs:string">
<my:enumeration value="Cinderella"/>
<my:enumeration value="Rupenzel"/>
<my:enumeration value="Black Beauty"/>
</my:restriction>
</my:simpleType>
</my:element>
|
|
|
|
|
My company uses XML received by email all the time to receive information from different sources everyday. I'm looking to improve the speed a little bit more as email has normally a delay. What's the best way to receive those forms? I created a webservice, however some of our providers do not want to spend the time building a solution. I would like something I can provide to them in order to received those forms.
Any ideas?
Al
My eMail control
My Blog
|
|
|
|
|
Hard to say what is "best" when you don't have all the information. Here is a wild guess. If you have a Web Server you could supply a web page that allows the user to Upload the file to your server.
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
Or really splash the cash and invest in biztalk...
|
|
|
|