|
WE agree you saved us......!
Thanx a lot from Greece
Vivi and Lefteris
|
|
|
|
|
Hello,
I use method CXmlDocumentWrapper::Save. When I open xml file in text editor I see:
<neuralnetwork><new_node somevalue3="Data_Item3">nodeText<new_node55>node5
Is it possibility to change xml formating text to
<neuralnetwork>
<new_node somevalue3="Data_Item3">nodeText
<new_node55>node5
Best regards
Mariusz K
|
|
|
|
|
Sorry to say but xml formating is not currently implemented...
To apply formating one needs to use XSL transformation on the document , similar to what Internet explorer does (check what happens when you open the xml document in IE)
One could write a method like "SaveFormated" which would apply a predefined XSL transformation on the document. I bealeave that there are ready XSL transforms on the internet that do that kind of transformation , if I'll get my hands free any time soon I'll write one myself and update the article.
Creative minds - create creative creations!
|
|
|
|
|
I have loaded the following XML into a String using the two lines of code shown below. I now need to extract the Address information of each candidate as a string. I have tried a few different methods but keep coming up with no value. Any idea I can populate the address information of each candidate into a string. Thanks in advance.
doc.Load( URL );
mGeoXML = doc.GetXML();
<?xml version="1.0" ?>
- <CdResults>
- <CdCandidates>
- <CdCandidate>
<txtStreet>A Street</txtStreet>
<txtCity>A City</txtCity>
<txtState>NY</txtState>
<txtZip>14150</txtZip>
<txtPlus4></txtPlus4>
<txtLon>-78.8728161862189</txtLon>
<txtLat>42.890780920576</txtLat>
<txtGeoResult>S5HPNTSC-A</txtGeoResult>
<txtFirm />
<txtCensusBlockId>360290072011012</txtCensusBlockId>
<txtPrecision>20</txtPrecision>
</CdCandidate>
- <CdCandidate>
<txtStreet>Street 2</txtStreet>
<txtCity>City 2</txtCity>
<txtState>NY</txtState>
<txtZip>14223</txtZip>
<txtPlus4></txtPlus4>
<txtLon>-78.7527337771572</txtLon>
<txtLat>42.8337338423022</txtLat>
<txtGeoResult>S5HPNTSC-A</txtGeoResult>
<txtFirm />
<txtCensusBlockId>360290118002005</txtCensusBlockId>
<txtPrecision>20</txtPrecision>
</CdCandidate>
-- modified at 10:28 Friday 17th February, 2006
|
|
|
|
|
Hello Alex,
Thanks for sharing your code, I'm learning a lot from it.
I would sugest that you add also into the article documentation the need of the CoInitialize() in order to work, I noticed this only after trying your code without success and then saw the use of CoInitialize() in your demo dialog application that was missing for me. (Confirmed by an answer you provided in this forum as well).
I noticed that the demo code is not synchronized with the latest XmlNodeWrapper.h and XmlNodeWrapper.h files, although it is not a problem to understand your code.
It will be nice also to provide with the demo the creation of an XML file using the different functions you have.
In the past I used the CMarkup[^], but I could not remove stuff on-the-fly from XML files, so I moved to .dan.g.[^] XmlFile from ToDoList[^]TodoList, but now, I'm happy to start using your code, although my knowledge with COM/DCOM is not strong enough yet..
Have a nice day.
-- Ricky Marek (AKA: rbid)
-- "Things are only impossible until they are not" --- Jean-Luc Picard
My articles
|
|
|
|
|
Hi, thanks for the module - it's a pretty one.
I've rewritten it a bit: changed CString to CStdString, so the module can be used without MFC, and changed char to TCHAR so it is now both ANSI and UNICODE compliant.
Want it as it is now?
|
|
|
|
|
Sorry, here is the xml file
<root> <participant>TEST
<envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<notifications xmlns="http://markets.midwestiso.org/dart/xml">
<dispatch interval="2005-10-17T22:30:00.000-05:00" location="CIN.DPLG.BECK6">
<dispatchmw>84
<price>25.54
<dispatch interval="2005-10-17T22:30:00.000-05:00" location="CIN.DPLG.EBEN2">
<dispatchmw>124
<price>25.43
<dispatch interval="2005-10-17T22:30:00.000-05:00" location="CIN.DPLG.MIAF7">
<dispatchmw>141
<price>25.47
<dispatch interval="2005-10-17T22:30:00.000-05:00" location="CIN.DPLG.MIAF8">
<dispatchmw>272
<price>25.81
<dispatch interval="2005-10-17T22:30:00.000-05:00" location="CIN.DPLG.ZIMM">
<dispatchmw>272
<price>25.81
Dave G
|
|
|
|
|
I am new to XML and would appreciate some help getting started using the XMLNodeWrapper. My XML document looks like this:
//*********************************************************************************************
-
- <root>
<participant>TEST
- <envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
-
- <notifications xmlns="http://markets.midwestiso.org/dart/xml">
- <dispatch interval="2005-10-17T22:30:00.000-05:00" location="SIN.APLG.HECK8">
<dispatchmw>84
<price>25.54
- <dispatch interval="2005-10-17T22:30:00.000-05:00" location="SIN.APLG.JBEN4">
<dispatchmw>124
<price>25.43
- <dispatch interval="2005-10-17T22:30:00.000-05:00" location="SIN.APLG.KIAF2">
<dispatchmw>141
<price>25.47
- <dispatch interval="2005-10-17T22:30:00.000-05:00" location="SIN.APLG.KIAF8">
<dispatchmw>272
<price>25.81
- <dispatch interval="2005-10-17T22:30:00.000-05:00" location="SIN.APLG.MIMM">
<dispatchmw>272
<price>25.81
//*********************************************************************************************
I have tried the following commands to retrieve the DispatchMW values but the szValue comes back NULL everytime. I really would like to retrieve each DispatchMW value per each location and store these values in a database. Any help would be appreciated.
//************************************************************
m_xmlDocument.Load("C:\\harris\\XML\\dispatch test.xml");
CXmlNodeWrapper root(m_xmlDocument.AsNode());
CXmlNodeWrapper myOutPutNode(root.FindNode("Dispatch/DispatchMW"));
CString szValue = myOutPutNode.GetText();
//************************************************************
Thanks in advance,
Dave G
|
|
|
|
|
Hello,
I need to create a new document, add nodes to it and save it.
How do I do it ?
How do I create a new node ?
How do I create a documnet from scratch?
Thanks,
jr.
|
|
|
|
|
Example:
CXmlDocumentWrapper doc;
doc.LoadXML("<root>");
CXmlNodeWrapper root(doc.AsNode());
CXmlNodeWrapper node(root.AddNode("New_Node"));
node.SetValue("SomeValue","Data_Item");
doc.Save("C:\\newdoc.xml");
Creative minds - create creative creations!
|
|
|
|
|
Hi
I'm also having problems creating a new XML document and saving it to file. The above code fails to compile, as AddNode is not a member of CXmlNodeWrapper? Also, doc.AsNode() returns NULL - is this to be expected?
Another example would be great, and would help to support this excellent XML wrapper class
|
|
|
|
|
I'm sorry for misleading you , since I was writing the above code from my memory , without actually looking at the source, and apparently my memory is not as good as I hoped it to be .
You should use "InsertNode" instead of "AddNode" (you can use -1 as an index to insert at the end).
Also the LoadXML function should load some actual XML string and not an empty string like it looks (the foeum engine must have stripped the XML tags away) , for example:
xmlDoc.LoadXML("<Root></Root>");
|
|
|
|
|
Hi,
I m just trying to use your wrapper to play with XML,
i just created a dialog application and tried to use Load function.
First of all i created CXmlDocumentWrapper m_xmlDoc; in the header file and then onOK function
i m calling m_xmlDoc.Load("C:\\sample.xml"); but when i debug i found out its returing at this line if (!IsValid())
return FALSE;
kidnly let me know, what do i have to do.
Regards,
-- modified at 13:24 Monday 17th October, 2005
|
|
|
|
|
Either your XML file is not well formed. Or there is some other error.
You should provide more code and the sample xml doc , for me to be able to help you.
Creative minds - create creative creations!
|
|
|
|
|
Thanks, just came cross to this article again....so noticed i forgot the reply it.
i was doing a silly mistake that why i was having that probolem...just explainig it here so that if any1else getting the same problem then it would be easy to get solution without spending hrs to located the problem.
Solution was straight forward since MSXML is COM base and we have to always Coinitialize it to NULL. So i had to just call CoInitialize(NULL) from InitInstance().
Regards,
|
|
|
|
|
Hi when I load the document I always get FALSE
My code:
m_xmlDoc.Load("Downloads.xml");
if (m_xmlDoc.IsValid()==TRUE) MessageBox("TRUE");
else MessageBox("FALSE");
Decleration of m_xmlDoc:
CXmlDocumentWrapper m_xmldoc;
When I opend the file with your program I can list the XML, but when I want to open the file with my program it dosnt work I also called CoIntialize(NULL) in InitInstance() and I always get FALSE message, I also included all of the headers that you included in your program.
PLZ help || advice && MessageBox("Have a nice Day ");
|
|
|
|
|
I changed the default ctor as follows, and it seems to pass the IsValid() function. Although I'm still having a problem loading a XML file..
CXmlDocumentWrapper::CXmlDocumentWrapper()
{
CoInitialize(NULL);
try
{
m_xmldoc = NULL;
m_xmldoc.CreateInstance(MSXML2::CLSID_DOMDocument);
}
catch(_com_error &e)
{
CString strError(_T(e.ErrorMessage()));
CString strDescription(_T((LPCSTR) e.Description()));
}
}
|
|
|
|
|
Hola a todos,
En especial a Alex Hazanov,
He probado tus XMLNodeWrapper.h y .cpp en mi aplicacion y no funciona, he llevado todo a la tuya y si me va, pero en la mia no, me falla en el
m_xmlDoc.Load()
no me lee la ruta que le pongo, la he puesto de mil formas y he visto que
BOOL CXmlDocumentWrapper::IsValid()
{
if (m_xmldoc == NULL)
{
AfxMessageBox("Hola");
return FALSE;
}
if (m_xmldoc.GetInterfacePtr() == NULL)
{
AfxMessageBox("Adios");
return FALSE;
}
return TRUE;
}
se me va en el primero, no se pq pero el m_xmldoc me dice q es null
pq es???
Que alguien me de una solucion, llevo mas de 1 mes con ese error y no me lo puedo permitir
Escribirme a ruespla@upvnet.upv.es
Gracias
|
|
|
|
|
Sorry my spanish is not as good as my programming skills
I can only guess that you are trying to use the document wrapper and you either fail to load a document or you are trying to use an uninitialized document.
So you must note that :
1. To load a document you have to call the Load() function passing a full path name to the xml file ==> xmlDoc.Load("C:\\Some Folder\\some_xml_doc.xml");
2. To use the document without an xml file (build it from scratch) you have to load in as an xml string at least the root node, without it the document will not have the root node ==> xmlDoc.LoadXML("<SomeRoot></SomeRoot>");
Creative minds - create creative creations!
|
|
|
|
|
Ruben,I guess you problem is that you forgot to to call CoInitialize(NULL) from InitInstance() ..or some other suitable place..
Now in spanish as well:Creo que tu problema es que te olvidaste de llamar a CoInitialize(NULL) desde InitInstance() ...o en otro lugar correspondiente
HTH (Hope that helps)
-- Ricky Marek (AKA: rbid)
-- "Things are only impossible until they are not" --- Jean-Luc Picard
My articles
|
|
|
|
|
Hello!
Here are a few more functions, perhaps useful to others. First off, I would suggest making all accessors const, and I also changed CString to std::string. For me, this was more convenient. Anyway, here are the functions:
<code>
string CXmlNodeWrapper::GetNamespaceURI() const
{
if( IsValid() )
{
_bstr_t str = static_cast<_bstr_t>(m_xmlnode->GetnamespaceURI());
return static_cast<char*>(str);
}
return "";
}
string CXmlNodeWrapper::GetNodeValue() const
{
if( IsValid() ) {
_bstr_t str = static_cast<_bstr_t>(m_xmlnode->GetnodeValue());
return static_cast<char*>(str);
}
return "";
}
MSXML2::IXMLDOMNodePtr CXmlNodeWrapper::InsertNode(int index, LPCTSTR nodeName, LPCTSTR nameSpace)
{
MSXML2::IXMLDOMDocumentPtr xmlDocument = m_xmlnode->GetownerDocument();
if (xmlDocument)
{
MSXML2::IXMLDOMNodePtr newNode = xmlDocument->createNode(_variant_t((short)MSXML2::NODE_ELEMENT), nodeName, nameSpace);
MSXML2::IXMLDOMNodePtr refNode = GetNode(index);
if (refNode)
newNode = m_xmlnode->insertBefore(newNode,_variant_t(refNode.GetInterfacePtr()));
else
newNode = m_xmlnode->appendChild(newNode);
return newNode;
}
return NULL;
}
void CXmlDocumentWrapper::CreateRootElement(LPCSTR name, LPCTSTR nameSpace)
{
MSXML2::IXMLDOMElementPtr pe;
pe = m_xmldoc->createNode("element", name, nameSpace);
if( pe!=NULL )
{
m_xmldoc->appendChild(pe);
pe.Release();
}
}
string CXmlDocumentWrapper::GetParseError() const
{
if( IsValid() )
{
MSXML2::IXMLDOMParseErrorPtr error = m_xmldoc->GetparseError();
boost::format f("Error:\nCode = 0x%1$x\nSource = Line: %2%, Char: %3%\nError Description = %4%");
_bstr_t bstrErr(error->Getreason());
f % error->GeterrorCode() % error->Getline() % error->Getlinepos() % (char*)bstrErr;
return f.str();
}
else
return "";
}
void CXmlDocumentWrapper::CreateProcessingInstruction(LPCTSTR target, LPCTSTR data)
{
MSXML2::IXMLDOMProcessingInstructionPtr pi;
pi = m_xmldoc->createProcessingInstruction(target, data);
if( pi!=NULL )
{
m_xmldoc->appendChild(pi);
pi.Release();
}
}
</code>
That's it.
Thanks for a great set of wrappers!
Daniel Lidström
|
|
|
|
|
Thanks Daniel.
I'm very happy to see that someone is not only blindly using the the wrapper (although that is perfectly OK , that was the intention), but also developing and farther enriching it.
Again , thank you very much.
Creative minds - create creative creations!
|
|
|
|
|
Hi Alex,
Why won't you update your excellent class with those ammenments then?
I'm observing it now to see how it will fit to my current application. If it will, you will absolutely get a 5!
Stilgar.
|
|
|
|
|
Sorry but I don't know how to create an xml like
<?xml verion = "1.0" encoding = "UTF-8"?>
<root>
<attb name = "1">
<ele name = "1.1">
</attb>
<attb name = "2">
<ele name = "2.1">
</attb>
</root>
I called:
doc.CreateProcessingInstruction("xml", "1.0");
doc.LoadXML("<root></root>");
...
but it didn't at <?xml = "1.0"?> at the beginning of the doc
I called:
doc.LoadXML("<root></root>");
doc.CreateProcessingInstruction("xml", "1.0");
...
it insert <?xml = "1.0"?> after <root> element.
Please help! Thank you in advanced!
|
|
|
|
|
Hello!
How do I access the node value of a text node. For example, the xml is this:
<?xml version="1.0" encoding="utf-8"?>
<Model mod_att1="val1" mod_att2="val2">__model_value__
<MainLine att1="val1" att2="val2">__mainline_value__
</MainLine>
</Model>
If I have a CXmlNodeWrapper pointing to the top element, Model, and I call GetText, then I receive a string with a value of
"__model_value__
__mainline_value__"
How do I get the value of the Model element? I'm only interested in the __model_value__ part.
Thanks in advance!
|
|
|
|