|
Are you calling CoInitialize?
Ref: Applications must initialize the COM library before they can call COM library functions. From the MSDN library.
HRESULT hr = CoInitialize(NULL);
bool bRetVal;
bRetVal=false;
IXMLHttpRequestPtr pIXMLHTTPRequest;
HRESULT hResult;
hResult = pIXMLHTTPRequest.CreateInstance("Microsoft.XMLHTTP");
//Test the connection
if ( FAILED(hResult) ) {
MessageBox("Fail to create the connection");
return bRetVal;
}
Workes fine for in a simple dialog initialization test.
"I will find a new sig someday."
|
|
|
|
|
|
Hi!
Will this code work with Managed C++/CLI also? What else need to be done to make this code work with Managed C++?
int _tmain(int argc, _TCHAR* argv[])
{
std::ostringstream XmlLogrequest;
XmlLogrequest << "<?xml version="
<< "\""
<< "1.0"
<< "\""
<< "?>"
<< "<request action = "
<< "\"registration"
<< "\""
<< ">"
<< "<element id="
<< "\"id001" << "\""
<< ">"
IXMLHTTPRequestPtr pIXMLHTTPRequest = NULL;
BSTR bstrString = NULL;
HRESULT hr = CoInitialize(NULL);
string test = XmlLogrequest.str().substr(0,XmlLogrequest.str().size());
cout << test<<"\n";
try {
hr=pIXMLHTTPRequest.CreateInstance("Msxml2.XMLHTTP.3.0");
pIXMLHTTPRequest->open("POST", "https://live.jqk365.com/cgibin/EClientIntegration",false);
hr=pIXMLHTTPRequest->send(test.c_str());
SUCCEEDED(hr) ? 0 : throw hr;
bstrString=pIXMLHTTPRequest->responseText;
MessageBox(NULL, _bstr_t(bstrString), _T("Results"), MB_OK);
if(bstrString)
{
::SysFreeString(bstrString);
bstrString = NULL;
}
} catch (...) {
MessageBox(NULL, _T("Error"), _T("Error"), MB_OK);
if(bstrString)
::SysFreeString(bstrString);
}
return 0;
}
|
|
|
|
|
Hi,
Using JavaScript, I want to visit all ChildNodes recursively and the tagName,getAttribute of each (if present).
Some may have a more depth of childNodes, some may not have.
Can somebody help me with a small codesnippet for the same.
I need this in JavaScript using Microsoft.XMLDOM
Thanks and Regards,
Deepak
Deepak Kumar Vasudevan
http://deepak.portland.co.uk/
|
|
|
|
|
What do u need? Do u need help with recursion? Do u need the API to the MSXML DOM? The latter can be found at msdn.microsoft.com/xml along with many samples.
"No matter where you go, there your are..." - Buckaoo Banzi
-pete
|
|
|
|
|
Hello all, this is my first project involving the use of XML data and I've run into a strange problem. First, here is the function I'm using to write a simple XML file:
public void writeXML() {
XmlTextWriter xml =
new XmlTextWriter("c:\\test.xml", System.Text.Encoding.UTF8);
xml.Formatting = Formatting.Indented;
xml.WriteStartDocument();
int i, j, iMax, jMax;
iMax = reportData.GetUpperBound(0);
jMax = reportData.GetUpperBound(1);
try {
for (i = 0; i <= iMax; i++) {
xml.WriteStartElement("transaction");
for (j = 0; j < jMax; j++) {
xml.WriteStartElement("item");
if (reportData[i,j] != null)
xml.WriteString(reportData[i,j].ToString().Trim());
xml.WriteEndElement();
}
xml.WriteEndElement();
}
xml.WriteEndDocument();
} catch (Exception ex) {
System.Console.Write(ex.ToString());
xml.Flush();
xml.BaseStream.Flush();
}
xml.Close();
}
NOTE: reportData is a two-dimensional array of objects that contains information from a CSV/text file.
The problem is that this code throws an exception the second time through the outer loop at the line 'xml.WriteStartElement("transaction");'. This is strange to me because the first "transaction" element and its "item" children are created fine, but the second "transaction" element errors out. Am I missing something in the XML rules? Anyway, here is the exception information:
System.InvalidOperationException: Token StartElement in state Epilog would result in an invalid XML document.
at System.Xml.XmlTextWriter.AutoComplete(Token token)
at System.Xml.XmlTextWriter.WriteStartElement(String prefix, String localName, String ns)
at System.Xml.XmlWriter.WriteStartElement(String localName)
at MerchantReport.MerchantReport.writeXML() in d:\projects\bearcub\merchantreporttransformation\merchantreport\merchantreport.cs:line 290
and here is the XML document created after I flush the stream:
<?xml version="1.0" encoding="utf-8"?>
<transaction>
<item>12345</item>
<item>A</item>
</transaction>
Any help in finding the problem is greatly appreciated.
|
|
|
|
|
and xml document can have only ONE root element, when you try and add the second transaction you are creating an invalid xml document, so you need to wrap it in a "<transactions>" element.
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Is there difference between XSL and XSLT or they just two name for one technology?
|
|
|
|
|
XSL is the group name for XSLT and XSLFO
really its XSL-T and XSL-FO
T was the transformation part - translating and xml document into another document.
FO was the formatting objects part - defines the presentation of an xml document for page layout.
however since XSL-FO took so long to arrive every tends to use XSL to mean XSLT.
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
I am using the XML namespace functions and classes in C# to create an XML file dynamically. However, when I look at the file in notepad, it's just one really really long string on the first line.
How do I include the appropriate newline and tab characters so that the file looks like a normal, logical XML file? I cant just use the normal "\n" character can I?
Do I use functions from the XmlWhitespace class or something??
|
|
|
|
|
You need to pass an XmlWriter to the Save method:
void SaveXml(XmlDocument doc, Stream s, Encoding encoding)
{
XmlTextWriter xtw = new XmlTextWriter(s, encoding);
xtw.Formatting = Formatting.Indented;
xtw.Indentation = 1;
xtw.IndentChar = '\t';
doc.Save(xtw);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
The C# code I'm using is shown below. The output file looks almost exactly how a basic XML file should look, I believe. My only concern is that how come the code to create it looks rather inefficient? How come I need to do "folder = doc.CreateElement("folder")" for EVERY new node that I create?? Can't I just use the "folder" object as a template for a folder element? Shouldnt all I need to do is set the attribute value and the inner text, and then reuse "folder" element object to append the new node? This is what I am saying:
<br />
XmlElement folder = doc.CreateElement("folder");<br />
<br />
folder.SetAttribute("name", "folder 1");<br />
folder.InnerText = "1st Node";<br />
root.AppendChild(folder);<br />
<br />
folder.SetAttribute("name", "folder 2");<br />
folder.InnerText = "2nd Node";<br />
root.AppendChild(folder);<br />
However, that did not work. Here's the (whole) code that does work for me:
<br />
XmlDataDocument doc = new XmlDataDocument();<br />
XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", null, null);<br />
doc.InsertAfter(declaration, null);<br />
<br />
XmlElement root = doc.CreateElement("file_system");<br />
doc.InsertAfter(root, declaration);<br />
<br />
XmlElement folder;<br />
<br />
folder = doc.CreateElement("folder");<br />
folder.SetAttribute("name", "folder 1");<br />
folder.InnerText = "1st Node";<br />
root.AppendChild(folder);<br />
<br />
folder = doc.CreateElement("folder");<br />
folder.SetAttribute("name", "folder 2");<br />
folder.InnerText = "2nd Node";<br />
root.AppendChild(folder);<br />
<br />
XmlTextWriter writer = new XmlTextWriter(@"d:\XMLTest.xml", null);<br />
doc.WriteTo(writer);<br />
writer.Close();<br />
Is this the correct and most efficient way to create an XML document dynamically? Please share with me better solutions. Thanks.
|
|
|
|
|
yep thats pretty much the best way to do it.
the reason you need to create and instance of folder (CreateFolder ) for each item is that AppendChild is appending a reference to the folder, rather than copying it.
the way you could speed/simply life is to create a template node and use CloneNode :
XmlElement templateFolder = doc.CreateElement("folder");<br />
XmlElement folder;<br />
<br />
folder = templateFolder.CloneNode();<br />
folder.SetAttribute("name", "folder 1");<br />
folder.InnerText = "1st Node";<br />
root.AppendChild(folder);<br />
<br />
folder = templateFolder.CloneNode();<br />
folder.SetAttribute("name", "folder 2");<br />
folder.InnerText = "2nd Node";<br />
root.AppendChild(folder);
hope this helps
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Hello everyone, I have this XML document and I need to store the content in a C/C++ structure. So far I can use MSXML to load the document and display it but how can I get it into C/C++ struct. I'm completely new to C/C++, can anyone help me to create a C/C++ struct to hold these data and also how to get the XML into the structure created. Many thanks!
<contact>
<personal>
<name>John Moss</name>
<age>28</age>
<house_number>8</house_number>
<street>Polygon Road</street>
<town>London</town>
<country>UK</country>
</personal>
<sport>
<style>Karate</style>
<belt>Second degree black belt</belt>
<champion>1992 1994 1995 1996</champion>
</sport>
</contact>
|
|
|
|
|
struct PERSONAL
{
CString szName;
int age;
int house_number;
CString szStreet;
CString szTown;
CString szCountry;
};
struct SPORT
{
CString szStyle;
CString szBelt;
CString szChampion;
};
struct CONTACT
{
PERSONAL personal;
SPORT sport;
};
void foo()
{
std::vector<CONTACT*> vpContacts;
for(int i=0; i<nContacts; i++)
{
vpContacts.push_back(new CONTACT);
vpContacts[i]->personal.szName = "Sam";
...
}
do_something(...);
vpContacts.clear();
}
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
>> I can use MSXML to load the document and display
>> it but how can I get it into C/C++ struct.
well once u have read the file into the MSXML document it is in a C/C++ structure. why would u want to copy the data into another one?
"No matter where you go, there your are..." - Buckaoo Banzi
-pete
|
|
|
|
|
sorry i already gave u this answer
"No matter where you go, there your are..." - Buckaoo Banzi
-pete
|
|
|
|
|
I am trying to document a class that I created with the built in XML Comments in VS.NET. I have this comment for my class:
/// <remarks>
/// Class representing a Binary Tree. Object instances inserted into this Binary Tree
/// must implement <seealso cref="System.IComparable"/>
/// </remarks>
It is my understanding that when a 'seealso' tag is encountered the compiler will create a link to the internal documentation for the class refereced with 'seealso'.
However this is not happening. It does not even print out the text 'System.IComparable' much less a link.
Is there something I am missing?
Or is my assumption wrong?
Thanks for your help!
|
|
|
|
|
This may be a bit long, but I will try to explain it clearly, so please read on.
I'm writing a web-based file management application (in ASP.NET/C#) that requires keeping track of a hierarchy of the names of folders and their files and subfolders (which may include their own files and subfolders). I need to store this whole organizational structure in memory at all times for quick access and modification. This structure will frequently need to be saved to a single file in some format (text, binary or xml) for storage after the application ends.
At first, I thought of using ArrayLists (one for folders and one for files). Each would be written as a single object into a binary file for storage. But I realize that it would be rather hard to manage nested folders using an ArrayList.
My next attempt is to keep track of the folders using a tree stucture. For instance, the 1st level child nodes will be the 1st level folders, and their children nodes can represent their subfolders, and so on. I need to be using a general tree, not a binary tree because a folder cna have more than 2 subfolders. However, I cannot find a Tree class in .NET anywhere. (There's not even a BinaryTree class).
But I did notice that an XML document resembles a general tree structure, which is what I need. My question is that is it possible and efficient for me to store a whole folder hierarchy in XML format?
I've never worked with XML documents before, but basically, I want to know if it possible for me to keep track of nested folders like this: (my syntax may be far from correct)
<folder name="Main Folder" folderCount="2" fileCount="1">
<folder name="Subfolder 1" folderCount="1" fileCount="0">
<folder name="Subfolder 1a" folderCount="0" fileCount="0">
</folder>
</folder>
<folder name="Subfolder 2" folderCount="0" fileCount="0">
</folder>
<file name="File 1">
</file>
</folder>
And remember, I need to be able to keep on adding as many levels of nested folders as I want. Am I able to do this with an XML structure? Also, can I dynamically add, remove or modify any folder?
MSDN says that ".NET XMLDocument class implements the W3C Document Object Model (DOM) Level 1 Core and the Core DOM Level 2. The DOM is an in-memory (cache) tree representation of an XML document and enables the navigation and editing of this document"
If I understand this correctly, it means that this "XML Document" is still an object stored in memory which will allow quick access. I can then write this object to an XML or binary file at any time.
.NET also has an easy way to load the data from the XMLDocument object into a DataSet. This can be very convenient for me because I can map this DataSet to a DataView and then display it on the screen using a DataGrid or DataList. That would be perfect.
OK. So would you suggest the XML method? Or should I just stop dreaming and find a way to manage nested folder using ArrayLists and DataTables? Please let me know. Thanks.
|
|
|
|
|
I would store your data within a class using std::vector to dynamically allocate your "branches" within the program. Then you can create a class using iostreams to write the data to a file in XML format. Then use something like PugXML (somewhere here on CP, I'm too lazy to look) to get the data back.
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Hi, can anyone help me please! I'm trying to load this sipmple XML into memory and then store the XML data into a structure so that my other programs can access this structure for retrieving data when needed. The XML document is:
<contact>
<personal>
<name>John Moss
<age>28
<house_number>8
<street>Polygon Road
<town>London
<country>UK
<sport>
Karate
<belt>Second degree black belt
<champion>1992 1994 1995 1996
So far I can only managed to load and display this document using (MSXML4)XMLLoad but how can I store these data into C/C++ structure? Please help as I'm completely terrible at C/C++ . Many thanks!!
|
|
|
|
|
>> but how can I store these data into C/C++ structure
well the document object ur creating using MSXML IS a tree structure so u already have one eh? if u need it to be in a different structure then can u expand on that?
"No matter where you go, there your are..." - Buckaoo Banzi
-pete
|
|
|
|
|
Hi Palbano, thank you very much for the reply, I understood that the DOM is already a tree struture, what I'd like to do is to transfer these data into another structure written in C/C++, which unfortunately I'm very terrible at. Would it be possible if you can show me how this is done by providing an example skeleton code. Much appreciated!
|
|
|
|
|
Say i had this ...
<A>
<B>data</B>
<C>
<D>first</D>
</C>
<C>
<D>second</D>
</C>
</A>
and I want this ...
<A>
<B>data</B>
<C>
<D>first</D>
</C>
</A>
What would be the xpath statement ?
something to do with C[1], but I am stumped after that
- james
|
|
|
|
|
something like 'ancestor-or-self::a/b/c[0]/d'. I can't remember, is it 0 or 1 based, the indexing ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
It'd probably be fairly easy to make a bot that'd post random stupid VB questions, and nobody would probably ever notice - benjymous - 21-Jan-2003
|
|
|
|