Skip to content

Commit

Permalink
Import of XANT/XML-TinyXML-0.09 from CPAN.
Browse files Browse the repository at this point in the history
gitpan-cpan-distribution: XML-TinyXML
gitpan-cpan-version:      0.09
gitpan-cpan-path:         XANT/XML-TinyXML-0.09.tar.gz
gitpan-cpan-author:       XANT
gitpan-cpan-maturity:     released
  • Loading branch information
Andrea Guzzo authored and Gitpan committed Oct 20, 2014
1 parent 1817cc8 commit 4e79570
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -17,3 +17,5 @@ Revision history for Perl extension TinyXML.
0.08 - bugfix : dexml() now works properly so special characters are now
handled correctly when importing xml data
- testunits now include escaping/unescaping-related checks
0.09 - bugfix : xmlize() MUST ensure to null-terminate the escaped string
if the buffer had to be realloc'd
2 changes: 1 addition & 1 deletion META.yml
@@ -1,7 +1,7 @@
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: XML-TinyXML
version: 0.08
version: 0.09
version_from: lib/XML/TinyXML.pm
installdirs: site
requires:
Expand Down
2 changes: 1 addition & 1 deletion lib/XML/TinyXML.pm
Expand Up @@ -137,7 +137,7 @@ our @EXPORT = qw(
XmlSubstBranch
);

our $VERSION = '0.08';
our $VERSION = '0.09';

sub AUTOLOAD {
# This AUTOLOAD is used to 'autoload' constants from the constant()
Expand Down
2 changes: 1 addition & 1 deletion lib/XML/TinyXML/Node.pm
Expand Up @@ -58,7 +58,7 @@ Reference to the underlying XmlNodePtr object (which is a binding to the XmlNode
package XML::TinyXML::Node;

use strict;
our $VERSION = '0.08';
our $VERSION = '0.09';

=item * new ($entity, $value, $parent, %attrs)
Expand Down
3 changes: 2 additions & 1 deletion t/TinyXML.t
Expand Up @@ -62,9 +62,10 @@ ok( $newhash->{hash}->{key2} eq $testhash->{hash}->{key2}, "nested hash member2"

$txml = XML::TinyXML->new();
$txml->addRootNode("nodelabel", "some'&'value", { attr1 => 'v>1', attr2 => 'v<2' });
print $txml->dump;
ok ( $txml->dump eq
q~<?xml version="1.0"?>
<nodelabel attr2="v&#60;2" attr1="v&#62;1">some&#39;&#38;&#39;value</nodelabel>
<nodelabel attr2="v&#60;2" attr1="v&#62;1">some&#39;&#38;&#39;value</nodelabel>
~, 'escaping');

$txml = XML::TinyXML->new();
Expand Down
43 changes: 31 additions & 12 deletions txml.c
@@ -1,5 +1,5 @@
/*
* tinyxml.c
* txml.c
*
* Created by xant on 2/17/06.
*
Expand Down Expand Up @@ -74,20 +74,24 @@ static char *dexmlize(char *string)
static char *xmlize(char *string)
{
int i, p = 0;
int len = strlen(string);
int len;
int bufsize;
char *escaped = NULL;

len = strlen(string);
if (string) {
escaped = calloc(1, len+1); // inlude null-byte
bufsize = len+1;
escaped = calloc(1, bufsize); // inlude null-byte
for (i = 0; i < len; i++) {
switch (string[i]) {
case '&':
case '<':
case '>':
case '"':
case '\'':
len += 4;
escaped = realloc(escaped, len+1);
bufsize += 5;
escaped = realloc(escaped, bufsize);
memset(escaped+p, 0, bufsize-p);
sprintf(&escaped[p], "&#%02d;", string[i]);
p += 5;
break;
Expand Down Expand Up @@ -276,6 +280,17 @@ void XmlClearAttributes(XmlNode *node)

}

XmlNodeAttribute *XmlGetAttributeByName(XmlNode *node, char *name)
{
int i;
for (i=1; i <= ListLength(node->attributes); i++) {
XmlNodeAttribute *attr = XmlGetAttribute(node, i);
if (strcmp(attr->name, name) == 0)
return attr;
}
return NULL;
}

XmlNodeAttribute *XmlGetAttribute(XmlNode *node, unsigned long index)
{
return PickValue(node->attributes, index);
Expand Down Expand Up @@ -608,7 +623,15 @@ XmlErr XmlParseBuffer(TXml *xml, char *buf)
int quote = *p;
p++;
mark=p;
while(*p!=quote && *p!=0) p++;
while(*p!=0) {
if (*p == quote) {
if (*(p+1) != quote) // handle quote escaping
break;
else
p++;
}
p++;
}
if(*p==quote) {
char *tmpVal = (char *)malloc(p-mark+2);
strncpy(tmpVal, mark, p-mark);
Expand Down Expand Up @@ -793,10 +816,7 @@ char *XmlDumpBranch(TXml *xml, XmlNode *rNode, unsigned int depth)
strcat(startTag, attr->name);
strcat(startTag, "=\"");
strcat(startTag, value);
if(i < nAttrs)
strcat(startTag, "\" ");
else
strcat(startTag, "\"");
strcat(startTag, "\"");
if (value)
free(value);
}
Expand All @@ -819,8 +839,7 @@ char *XmlDumpBranch(TXml *xml, XmlNode *rNode, unsigned int depth)
}
}
}
}
else {
} else {
// TODO - allow to specify a flag to determine if we want white spaces or not
strcat(startTag, ">");
}
Expand Down

0 comments on commit 4e79570

Please sign in to comment.