Skip to content

Commit

Permalink
Fix cases where the program would generate incorrect parsing code for…
Browse files Browse the repository at this point in the history
… elements and attributes with disallowed characters

One example of this is if you have an element <foo-bar>. The generated code
for this would attempt to find and parse <foo_bar> instead.
  • Loading branch information
Tjoppen committed Sep 3, 2013
1 parent e9f1ea4 commit 99016ca
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Class.cpp
Expand Up @@ -159,10 +159,10 @@ string Class::generateAppender() const {

if(it->isAttribute) {
//attribute
oss << it->cl->generateAttributeSetter(name, subName, et);
oss << it->cl->generateAttributeSetter(it->xmlName, subName, et);
} else {
//element
oss << it->cl->generateElementSetter(subName, name, et);
oss << it->cl->generateElementSetter(subName, it->xmlName, et);
}
}

Expand Down
1 change: 1 addition & 0 deletions Class.h
Expand Up @@ -46,6 +46,7 @@ class Class {
class Member {
public:
std::string name;
std::string xmlName;
FullName type;
Class *cl; //NULL is class is unknown (only allowed for optionals and vectors)
int minOccurs;
Expand Down
17 changes: 11 additions & 6 deletions main.cpp
Expand Up @@ -245,7 +245,8 @@ static void parseSequence(DOMElement *parent, DOMElement *sequence, Class *cl, b
XercesString typeStr("type");
XercesString minOccursStr("minOccurs");
XercesString maxOccursStr("maxOccurs");
string name = fixIdentifier(XercesString(child->getAttribute(XercesString("name"))));
string elementName = XercesString(child->getAttribute(XercesString("name")));
string identifierName = fixIdentifier(elementName);

if(child->hasAttribute(minOccursStr)) {
stringstream ss;
Expand Down Expand Up @@ -276,7 +277,8 @@ static void parseSequence(DOMElement *parent, DOMElement *sequence, Class *cl, b
//has type == end point - add as member of cl
Class::Member info;

info.name = name;
info.name = identifierName;
info.xmlName = elementName;
//assume in same namespace for now
info.type = toFullName(XercesString(child->getAttribute(typeStr)));
info.minOccurs = minOccurs;
Expand All @@ -287,13 +289,14 @@ static void parseSequence(DOMElement *parent, DOMElement *sequence, Class *cl, b
} else {
//no type - anonymous subtype
//generate name
FullName subName(cl->name.first, cl->name.second + "_" + (string)name);
FullName subName(cl->name.first, cl->name.second + "_" + identifierName);

//expect <complexType> sub-tag
parseComplexType(getExpectedChildElement(child, "complexType"), subName);

Class::Member info;
info.name = name;
info.name = identifierName;
info.xmlName = elementName;
info.type = subName;
info.minOccurs = minOccurs;
info.maxOccurs = maxOccurs;
Expand Down Expand Up @@ -361,7 +364,8 @@ static void parseComplexType(DOMElement *element, FullName fullName, Class *cl)
if(!child->hasAttribute(XercesString("name")))
throw runtime_error("<attribute> missing expected attribute 'name'");

string attributeName = fixIdentifier(XercesString(child->getAttribute(XercesString("name"))));
string attributeName = XercesString(child->getAttribute(XercesString("name")));
string identifierName = fixIdentifier(attributeName);

FullName type = toFullName(XercesString(child->getAttribute(XercesString("type"))));

Expand All @@ -370,7 +374,8 @@ static void parseComplexType(DOMElement *element, FullName fullName, Class *cl)
optional = true;

Class::Member info;
info.name = attributeName;
info.name = identifierName;
info.xmlName = attributeName;
info.type = type;
info.isAttribute = true;
info.minOccurs = optional ? 0 : 1;
Expand Down

0 comments on commit 99016ca

Please sign in to comment.