|
Thanks bro..
your input has helped me lot... now it is working perfectly fine...
whereas after revising of my requirment i came to know that the top nodes "Data" and "User" are constant and it's child will varies...
so i modified the code like this:
XNode xmlOutput;
xmlOutput.Load("<Data><User></User></Data>");
LPXNode nodeUser = xmlOutput.GetChild("User");
nodeUser->AppendChild("FirstName", "Sharath");
nodeUser->AppendChild("LastName", "Kumar");
// may have some more child...
string strOutput = xmlOutput.GetXML();
// finally i want to save the result in file...
XML* xmlvalue = new XML(strOutput.c_str(),1,0,0);
xmlvalue->Save("OutputRecord.xml",1,0,0,0);
delete xmlvalue;
It is working correct as per my requirment..
Now i just want to know, is this method correct. I want to make sure that it is good interms of performence and there should not be any memory leak.
please give me your input...
Thanks
sharath
|
|
|
|
|
I've been using xmlite in VC6 for many years now and its been a real pleasure.
Now we are forced to move to a new compiler and found that xmlite does not compile with the new version. The problem is the NULL assignment to a vector::iterator.
Before I go and fix the library to not check for NULL in its iterators and return something like ::end() instead of NULL I would like to know if someone has already done this and made the new version of the code available?
Thanks
Peter
|
|
|
|
|
|
|
such as a xml <AddressBook><Person type='friend'/><Person type='man'/><Information count='3'/></AddressBook> I want set as informationcount 5,and increase a child <Person type='boy'/>
I find some methods in xmllite
// modify DOM
XNodes::iterator GetChildIterator( LPXNode node );
LPXNode CreateNode( LPCTSTR name = NULL, LPCTSTR value = NULL );
LPXNode AppendChild( LPCTSTR name = NULL, LPCTSTR value = NULL );
LPXNode AppendChild( LPXNode node );
bool RemoveChild( LPXNode node );
LPXNode DetachChild( LPXNode node );
// modify attribute
LPXAttr GetAttr( int i );
XAttrs::iterator GetAttrIterator( LPXAttr node );
LPXAttr CreateAttr( LPCTSTR anem = NULL, LPCTSTR value = NULL );
LPXAttr AppendAttr( LPCTSTR name = NULL, LPCTSTR value = NULL );
LPXAttr DetachAttr( LPXAttr attr );
use these methods?
|
|
|
|
|
you can easily modify value/text of node (element or attr or PI) like below
// load xml
XNode xml;
xml.Load( "<AddressBook><Person type='friend'/><Person type='man'/><Information count='3'/></AddressBook>");
// now, xml is AddressBook node.
// get Infomation (it is child of AddressBook node.
LPXNode pInfo = xml.GetChild("Information");
// modify count to 5 (count is attribute of Infomation
LPXAttr pCount= pInfo->GetAttr("count");
pCount->value = _T("5");
// pCount->text = _T("count2"); text change
// make person node.
// also you can use pInfo->CreateNode(), actually it's eual.
LPXNode pChild = new XNode;
pChild->name = _T("Person");
// now append attr to person
pChild->AppendAttr(_T("type"), _T("boy"));
// append person to addressbook
xml.AppendChild( pChild );
// see xml
AfxMessageBox( xml.GetXML() );
I hope it helps with u.
I didn't compile upper code. but i think it may works.
please reply the result for helping me and others.
thanks.
Thank you all. No one know oneself all. My idea from you, book, all others. already we are shared brains.
modified on Wednesday, September 17, 2008 11:35 PM
|
|
|
|
|
thanks I have done it in this way .now i want a tag to xml string .such as "<AddressBook><Person type='friend'/><Person type='man'/><Information count='3'/></AddressBook>"); I want add <?xml version='1.0' ?> now xml string is <?xml version='1.0' ?>"<AddressBook><Person type='friend'/><Person type='man'/><Information count='3'/></AddressBook>
finally save this xml string as test.xml
I don't know how to add <?xml version='1.0' ?> . Can you help me ??
thanks !
|
|
|
|
|
|
If you want to add PI node ( stuff), then you should use XDoc instead of XNode.
XDoc has one root element node. you can access with using XDoc::GetRoot().
and other node like PI is child of XDoc.
XDoc is equal with XNode. but XDoc has another function, it is container of PI. (it's same to MSXML )
so, you can do like below.
XDoc doc;
// make
XNode* pPI = new XNode;
pPI->name = "xml";
pPI->type = XNODE_PI;
pPI->CreateAttr( "version", "1.0" );
doc.AppendChild( pPI );
// make root element node
XNode* pRoot = new XNode;
// you might know how to build childs of pRoot.
// plz check my previous answer.
doc.AppendChild( pRoot );
AfxMessageBox( doc.GetXML() );
and, this time also, i didn't compile upper code. just type on online, plz don't blame some errors..
Thanks for using.
ps. you can get string with GetXML() member function of XDoc or XNode.
once you get the string of XML, then u can save to file by using fopen/fwrite stuff
Thank you all. No one know oneself all. My idea from you, book, all others. already we are shared brains.
|
|
|
|
|
Can xmlite Load xml files ??such as temp.xml??
|
|
|
|
|
you can load xml from file like below example.
int LoadFromFile(char* fpath, char* buf)
{
FILE* fp;
fp = fopen(fpath, "rt");
if( fp == NULL)
return 0;
fread(buf, 1, 1000, fp );
fclose(fp);
return 1;
}
void CTestXMLiteDlg::OnButton13()
{
// TODO: Add your control notification handler code here
char buf1[1000];
char buf2[1000];
XNode node1;
XNode node2;
if( LoadFromFile("a.xml", buf1) == 0 )
{
AfxMessageBox("no file a.xml");
return;
}
node1.Load( buf1 );
Thank you all. No one know oneself all. My idea from you, book, all others. already we are shared brains.
|
|
|
|
|
"We are currently using XMLite in our MavBridge product,
which converts scanner data files between various formats (many of which
are XML). The code has worked very well, and has been very easy to use."
MAVRO IMAGING LLC
www.MavroImaging.com
They sended thanks mail to me.
I hope xmlite can help with their work.
I will add to reference section.
Thank you all. No one know oneself all. My idea from you, book, all others. already we are shared brains.
|
|
|
|
|
I've to read XML Data from an URL using C++. How can I do this?
|
|
|
|
|
you can download from url like below: (MFC version, but you can easily find, Win32 version, or socket version on googling)
just modify that function to save string.
BOOL SaveImage(LPCTSTR szImgPath)
{
CInternetSession is;
CInternetFile* pif = NULL;
HANDLE hFile = NULL;
pif = (CInternetFile*)is.Openurl(szImgPath, 1, INTERNET_FLAG_TRANSFER_BINARY);
if ( pif == NULL )
return FALSE;
CHAR szLocalFile[255];
wsprintf(szLocalFile, "C:\\%s", pif->GetFileName());
hFile = CreateFile(szLocalFile, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
if ( hFile == INVALID_HANDLE_VALUE )
{
pif->Close();
is.Close();
return FALSE;
}
while(1)
{
INT nRead = 0;
DWORD dwWritten = 0;
CHAR szBuffer[255];
nRead = pif->Read(szBuffer, 255);
if ( nRead == 0 )
break;
WriteFile(hFile, szBuffer, nRead, &dwWritten, NULL);
}
CloseHandle(hFile);
pif->Close();
is.Close();
return TRUE;
}
Thank you all. No one know oneself all. My idea from you, book, all others. already we are shared brains.
|
|
|
|
|
How can i read a specific file with XMLite?
I am new with C++ and i have to do this as soon as possible! please help
|
|
|
|
|
just you can read file to string variable. and load that xml string to xmlite.
char sXml[1000];
FILE* fp = fopen("some.xml", "rt");
long filesize = ftell(fp);
fread(sXml, sizeof(char), filesize, fp);
then you have xml string. and load to xmlite
Thank you all. No one know oneself all. My idea from you, book, all others. already we are shared brains.
|
|
|
|
|
Hello,
I would like to know the memory constraint of this parser on mobile platform (planning to use for WM).
The avg size of the XML file to be fed to the parser would be 50KB.
Any suggestions or inputs would be highly appreciated.
Thnkz,
Zoom
|
|
|
|
|
You might be better off with CMarkup, we found this much quicker to load in a large XML file as it only points to elements, attributes in the file rather than copying them. So uses little additional memory to the size of the file itself.
www.firstobject.com/xmleasy.htm
|
|
|
|
|
Just wondered why XMLite impliments the CDATA in the way it does, (a child of a child) is this a normal implementation.
I have the XML line
"<Parameter><![CDATA[Window 1]]></Parameter>"
and in order to get the value of the Parameter, I have to do the following:
pAttributeChild = GetChild("Parameter");
strValue = pAttributeChild->GetChildValue("#CDATA");
I thought I would be able to do:
strValue = pAttributeChild->GetChildValue("Parameter");
as I do for all values that are not encapsulated in the CDATA.
Thanks
Ian
|
|
|
|
|
Yes. I made that node name with "#CDATA".
you can see that function on LoadCDATA.
LPTSTR xml = (LPTSTR)pszXml;
xml += sizeof(szXMLCDATAOpen)-1;
LPXNode node = new XNode;
node->parent = this;
node->doc = doc;
node->type = XNODE_CDATA;
node->name = _T("#CDATA");
_SetString( xml, end, &node->value, FALSE );
par->childs.push_back( node );
If you want, then modify that code for your purpose. and if I have some mistake or miss-standard. then just modify and share that. thanks.
but i wonder, if 'Parameter' node have CDATA and value text like below:
"<Parameter>Value of Parameter<![CDATA[Window 1]]></Parameter>"
then which one (Value of Parameter and CDATA stuff) can be selected for Parameter's value?
Thank you all. No one know oneself all. My idea from you, book, all others. already we are shared brains.
|
|
|
|
|
We have chosen to stick with your current implementation for now.
Thanks
Ian
|
|
|
|
|
Anybody has this working on Visual Studio 2005?
|
|
|
|
|
XNodes::iterator _tagXMLNode::GetChildIterator( LPXNode node )<br />
{<br />
XNodes::iterator it = childs.begin();<br />
for( ; it != childs.end() ; ++(it) )<br />
{<br />
if( *it == node )<br />
return it;<br />
}<br />
return NULL; <br />
}<br />
|
|
|
|
|
you can find that fix in other's reply.
Thank you all. No one know oneself all. My idea from you, book, all others. already we are shared brains.
|
|
|
|
|
Good work. Yet I realize that this isn't a standard-compliant code. XMLite.cpp at line 330 throws me an error: 'i' undeclared identified. You have the following code:
for( int i = 0 ; i < childs.size(); i ++)
{
...
}
childs.clear();
for( i = 0 ; i < attrs.size(); i ++)
{
...
}
While compiling it with VC8 it throws me 7 errors and 17 warnings.
Regards.
Hope is the negation of reality - Raistlin Majere
|
|
|
|