mirror of https://github.com/AxioDL/tinyxml2.git
attribute support
This commit is contained in:
parent
ec975cede8
commit
22aead1c73
|
@ -288,6 +288,9 @@ char* XMLComment::ParseDeep( char* p )
|
||||||
// --------- XMLAttribute ---------- //
|
// --------- XMLAttribute ---------- //
|
||||||
char* XMLAttribute::ParseDeep( char* p )
|
char* XMLAttribute::ParseDeep( char* p )
|
||||||
{
|
{
|
||||||
|
p = ParseText( p, &name, "=" );
|
||||||
|
if ( !p || !*p ) return 0;
|
||||||
|
|
||||||
char endTag[2] = { *p, 0 };
|
char endTag[2] = { *p, 0 };
|
||||||
++p;
|
++p;
|
||||||
p = ParseText( p, &value, endTag );
|
p = ParseText( p, &value, endTag );
|
||||||
|
@ -298,7 +301,8 @@ char* XMLAttribute::ParseDeep( char* p )
|
||||||
|
|
||||||
void XMLAttribute::Print( FILE* cfile )
|
void XMLAttribute::Print( FILE* cfile )
|
||||||
{
|
{
|
||||||
fprintf( cfile, "\"%s\"", value );
|
// fixme: sort out single vs. double quote
|
||||||
|
fprintf( cfile, "%s=\"%s\"", name.GetStr(), value.GetStr() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -351,7 +355,7 @@ char* XMLElement::ParseDeep( char* p )
|
||||||
}
|
}
|
||||||
|
|
||||||
// attribute.
|
// attribute.
|
||||||
if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) {
|
if ( IsAlpha( *p ) ) {
|
||||||
XMLAttribute* attrib = new XMLAttribute( this );
|
XMLAttribute* attrib = new XMLAttribute( this );
|
||||||
p = attrib->ParseDeep( p );
|
p = attrib->ParseDeep( p );
|
||||||
if ( !p ) {
|
if ( !p ) {
|
||||||
|
@ -459,6 +463,7 @@ bool XMLDocument::Parse( const char* p )
|
||||||
charBuffer = CharBuffer::Construct( p );
|
charBuffer = CharBuffer::Construct( p );
|
||||||
XMLNode* node = 0;
|
XMLNode* node = 0;
|
||||||
|
|
||||||
|
// fixme: clean up
|
||||||
char* q = Identify( this, charBuffer->mem, &node );
|
char* q = Identify( this, charBuffer->mem, &node );
|
||||||
while ( node ) {
|
while ( node ) {
|
||||||
root->InsertEndChild( node );
|
root->InsertEndChild( node );
|
||||||
|
|
|
@ -169,6 +169,7 @@ public:
|
||||||
private:
|
private:
|
||||||
char* ParseDeep( char* p );
|
char* ParseDeep( char* p );
|
||||||
|
|
||||||
|
StrPair name;
|
||||||
StrPair value;
|
StrPair value;
|
||||||
XMLAttribute* next;
|
XMLAttribute* next;
|
||||||
};
|
};
|
||||||
|
|
BIN
tinyxml2.suo
BIN
tinyxml2.suo
Binary file not shown.
|
@ -28,13 +28,15 @@ int main( int argc, const char* argv )
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
static const char* test[] = { "<!--single element-->",
|
static const char* test[] = { //"<!--single element-->",
|
||||||
"<element />",
|
"<element />",
|
||||||
"<element></element>",
|
"<element></element>",
|
||||||
"<!--single sub-element-->",
|
//"<!--single sub-element-->",
|
||||||
"<element><subelement/></element>",
|
"<element><subelement/></element>",
|
||||||
"<element><subelement></subelement></element>",
|
"<element><subelement></subelement></element>",
|
||||||
"<!--comment beside elements--><element><subelement></subelement></element>",
|
"<!--comment beside elements--><element><subelement></subelement></element>",
|
||||||
|
"<!--comment beside elements, this time with spaces--> \n <element> <subelement> \n </subelement> </element>",
|
||||||
|
"<element attrib1='foo' attrib2=\"bar\" ></element>",
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
for( int i=0; test[i]; ++i ) {
|
for( int i=0; test[i]; ++i ) {
|
||||||
|
|
Loading…
Reference in New Issue