|
|
Comments and Discussions
|
|
 |

|
Sure, parsing any document (even ill-formed ones) seems like a good idea, but it will bite you in the future. Such as when you need the processor not to strip whitespace from strings, violating the XML spec.
|
|
|
|

|
There are some potential buffer overflows that corrupt the call stack, when converting huge double values into text representation. A buffer size of 32 character is too small. I have replaced the value 32 with _CVTBUFSIZE from stdlib.h.
xml_attribute& operator=(double rhs)
{
TCHAR temp[_CVTBUFSIZE + 1] = {0}; _stprintf(temp,_T("%lf"),rhs);
value(temp);
return *this;
}
and
xml_attribute append_attribute(const TCHAR* name,double value)
{
if(!name) return false;
TCHAR temp[_CVTBUFSIZE + 1] = {0}; _stprintf(temp,_T("%lf"),value);
return append_attribute(name,temp);
}
Thomas Haase
|
|
|
|
|

|
Hi!
This library would be a great if it worked!
I tried to compile a small application, taking into account the above comments, but it does not work. It compiles but does not work.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <ostream>
#include <pugxml.h>
using namespace std;
using namespace pug;
int _tmain(int argc, _TCHAR* argv[])
{
xml_parser* xml = new xml_parser;
xml_node root = xml->document();
xml_node node = root.append_child(pug::node_element);
node.name(_T("node"));
node.value(_T("my name is root"));
wcout<<node.value()<<endl;
xml_node d = root.first_element_by_name(_T("node"));
wcout<<d.value(); system("pause");
return 0;
}
Share your "Hello,World!" application please.
The demo don't work.
|
|
|
|

|
For some reason or another, root != document. Instead, attach a root to the document, then all the children to root. pug::xml_node_struct *doc = pug::new_node(pug::node_document); doc->parent = doc; pug::xml_node docNode(doc); pug::xml_node root = docNode.append_child(pug::node_element); root.name("TestData"); root.append_attribute("version", "1"); std::ostringstream str_xml_out; str_xml_out << docNode; std::string str_xml_out_str = str_xml_out.str(); returns: <TestData version="1"/> Maybe there's even a smaller version of the above.
-- Modified Friday, September 10, 2010 9:36 AM
|
|
|
|

|
Has anyone figured out how to get PugXML to compile under VS2010?
When I try it, the compiler doesn't find template class std::_Ranit<> that is used as the base class for xml_iterator.
When I look at MFC's xutility header file (where _Ranit was defined) it seems that there have been major changes since VS2008.
Templates are not my strong point and I'm having trouble understanding what changes are needed.
If anyone figures this out please post...modified on Tuesday, February 16, 2010 10:28 AM
|
|
|
|
|

|
1) I didn't lose any time with PugXML. Quite the opposite, it saved me a huge amount of time.
2) If I was starting from scratch I would take a look at your parser, but PugXML has been up and running for years in my application and there's no advantage to re-engineering and re-testing my app at this point.
3) You misspelled the word "lose".
|
|
|
|

|
Simply change the platform toolset back to v90, then it compiles again.
Property Pages
-> Configuration Properties
-> General
Cheers, Roland
|
|
|
|

|
Thanks, but I need to be able to compile my app with the V100 toolset.
Another solution was posted in a related article "XMLLib for PUGXML with XPath".
Tim.
|
|
|
|

|
There seems to be a workaround, posted in another article that is based on pugxml:
XMLLib for PUGXML with XPath
In our context this suggestion works for both Visual Studio 2005 and 2010.
Thomas Haase
|
|
|
|

|
The code does not compile with UNICODE macro set on because you use TCHAR (that is wchar_t in Unicode) and std::string at the same time instead of std::wstring for UNICODE version.
Anyway, thanks for sharing!
|
|
|
|

|
Hi, I am new to XML files and its interpretation. I have an application (C++) that has to read data from an xml file. my xml file format <game name="race"> <min_credit>10.00</min_credit> <max_win>15.00</max_win> <volume>off</volume> </game> I want to read the values for each attribute in game with name = race How to do this? I have spent 1 full day reading the docs but cudnt succeed .. Ne help is very much appreciated
|
|
|
|

|
deepti_v25 wrote: I want to read the values for each attribute in game with name = race
How to do this?
There isn't a built-in way to to do this, although there is a function all_elements_by_bme which you could copy, paste and edit to do the same thing for attributes.
|
|
|
|

|
Hi,
I'm having a hard time trying to use the iterators with standard algorithms.
for example the following line always causes runtime errors in the destructor of forward_class:
xml_node::child_iterator iter = find(Node.children_begin(), Node.children_end(), srchr);
where srchr can be any type I have a comparison operator defined for.
Are the iterators explicitly not for use with standard algorithms, or is there a trick to it?
I'm using the member functions now, but I thought it would be nice to use the same algo's as in other parts of the code.
Rgds
Richi
|
|
|
|

|
hi
I am looking for a very small less then 100Kb size C or C++ based XML parser. Can you tell me that how Pug XML can help me in solving my problem.
Regards
|
|
|
|

|
Hello,
I compiled your code with Visual Studio 2005 and get the following errors:
1>d:\devtemp\pugxml\pugxml.h(338) : error C2065: 'i' : undeclared identifier
1>d:\devtemp\pugxml\pugxml.h(2385) : error C2666: 'pug::xml_node::has_name' : 2 overloads have similar conversions
1> d:\devtemp\pugxml\pugxml.h(2390): could be 'bool pug::xml_node::has_name(const TCHAR *) const'
1> d:\devtemp\pugxml\pugxml.h(2385): or 'bool pug::xml_node::has_name(const std::string &)'
1> while trying to match the argument list '(const char *)'
1> note: qualification adjustment (const/volatile) may be causing the ambiguity
1>d:\devtemp\pugxml\pugxml.h(3161) : error C2666: 'pug::xml_node::has_name' : 2 overloads have similar conversions
1> d:\devtemp\pugxml\pugxml.h(2390): could be 'bool pug::xml_node::has_name(const TCHAR *) const'
1> d:\devtemp\pugxml\pugxml.h(2385): or 'bool pug::xml_node::has_name(const std::string &)'
1> while trying to match the argument list '(TCHAR *)'
1> note: qualification adjustment (const/volatile) may be causing the ambiguity
1>d:\devtemp\pugxml\pugxml.h(3441) : error C2065: 'j' : undeclared identifier
I have enabled in the project settings "Force Conformance In For Loop Scope".
The C++ standard says that a variable declared in a for loop shall go out of scope after the for loop ends.
Andreas.
|
|
|
|

|
I Use Visual Studio 2005 also have the same problem,
anyone can help me
thanks
|
|
|
|

|
This problem is easy to fix. Just declare i variable before first for in each function that contains for.
for(long i=1; i<n; ++i) {
}
for (i=1; i<n; ++i) {
}
Fix:
long i = 0; for(i=1; i<n; ++i) {
}
for (i=1; i<n; ++i) {
}
|
|
|
|

|
I was hoping that there would be a "latest" version on the site, with all bug fixes etc.
I'm thinking I might have to manually go though all the pages and make the fixes myself.
The original person involved doens't seem to be involved anymore, though Neville Franks seems to have been involved since the beginning. Is there anyway we can have a later version on the web that is maintained in some fashion (like on sourceforge)?
(or have people mostly found a better solution than pugxml?)
Magic
|
|
|
|

|
how to use outer_xml to output xml content?
angus
|
|
|
|

|
The following code will write from a memory mapped xml file to a disk file:
xml_node defNode = xml->document().first_element_by_name(_T("DopplerDefinitions"));
wofstream xmlout("C:\\temp\\foobar.xml", ios_base::out);
defNode.outer_xml(xmlout);
xmlout.close();
Note: wofstream used for UNICODE compile, ofstream should work w/o UNICODE.
|
|
|
|

|
I have adapated the following code:
pjharren wrote: The following code will write from a memory mapped xml file to a disk file:
xml_node defNode = xml->document().first_element_by_name(_T("DopplerDefinitions"));
wofstream xmlout("C:\\temp\\foobar.xml", ios_base::out);
defNode.outer_xml(xmlout);
xmlout.close();
using iostream, but I get the following compiler error:
"error C2440: 'type cast' : cannot convert from 'class ofstream' to 'class std::basic_ostream'
The target type has no constructors"
Any help would be appreciated. Thanks
|
|
|
|

|
I get errors when I attempt to compile using VC6 with UNICODE. I searched this forum but cannot resolve the problem. The errors are:
C:\DOCUMENTS AND SETTINGS\PATRICK HARREN\MY DOCUMENTS\VISUAL STUDIO PROJECTS\PugXMLMFC\pugxml.h(1921) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'unsigned short *' (or there is no acceptable conversion)
C:\DOCUMENTS AND SETTINGS\PATRICK HARREN\MY DOCUMENTS\VISUAL STUDIO PROJECTS\PugXMLMFC\pugxml.h(1990) : error C2664: 'bool __thiscall pug::xml_attribute::value(const unsigned short *)' : cannot convert parameter 1 from 'const char *' to 'const unsig
ned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\DOCUMENTS AND SETTINGS\PATRICK HARREN\MY DOCUMENTS\VISUAL STUDIO PROJECTS\PugXMLMFC\pugxml.h(2032) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'const unsigned short *' (or there is no acceptable conver
sion)
C:\DOCUMENTS AND SETTINGS\PATRICK HARREN\MY DOCUMENTS\VISUAL STUDIO PROJECTS\PugXMLMFC\pugxml.h(3131) : error C2440: 'default argument' : cannot convert from 'unsigned short [2]' to 'const class std::basic_string,c
lass std::allocator > &'
Reason: cannot convert from 'unsigned short [2]' to 'const class std::basic_string,class std::allocator >'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\DOCUMENTS AND SETTINGS\PATRICK HARREN\MY DOCUMENTS\VISUAL STUDIO PROJECTS\PugXMLMFC\pugxml.h(3131) : error C2548: 'first_element_by_path' : missing default parameter for parameter 2
All assistance will be much appreciated.
Thanks,
Pat Harren
pjharren@sbcglobal.net
|
|
|
|

|
Hi there.
I'am exploring this pugXML and I'm very impressed by the job done.
I have a very simple question about attributes:
I would like to delete an attribute named "ID" on every single element (if this attribute is present of course) of my XML file but I don't understand how to use
"attribute_iterator attributes_erase(attribute_iterator where)".
Could anyone help me ?
In advance, thanks
Michel
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
Discussion of techniques for fast, robust, light-weight XML parsing.
| Type | Article |
| Licence | |
| First Posted | 11 Jan 2003 |
| Views | 692,964 |
| Bookmarked | 277 times |
|
|