this is my first question, so plz don't be angry if I do sth. wrong.
I'm using xerces-c-3.1.4 with c++11 (g++ 6.2.0 20161005) and I have problems reading attributes from XML tags by name. I'm using the DOMParser. The follwing is the XML tag I'm reading.
<gui subtype="somethingsomething" prettyname="myPrettyName" docroot=".." listenip="0.0.0.0" listenport="1234" autostart="true">
In my program I read from it as follows:
char *prettyname = MyHelpers::XMLCh2Ch(attrmap->getNamedItem(MyHelpers::String2XMLCh(CT_GUI_NAME))->getNodeValue());
With the "prettyname" attribute it works all fine but if I try to read any other attribute such as "docroot" of this element by name I get a nullpointer by calling getNamedItem(...).
I know they are there, because if I read them in a loop (like below), everything is there.
for (XMLSize_t t = 0; t < attrmap->getLength(); t++) {
std::cout << "attr:\n" << MyHelpers::XMLCh2String(attrmap->item(t)->getNodeName()) << " : " << MyHelpers::XMLCh2String(attrmap->item(t)->getNodeValue()) << std::endl;
}
Now the weirdest part: I tried around a little bit with the names of the attributes to exclude the possibility tha I just hit a keyword which causes strange behavior. This made me recognize that it works fine when the attribute is not known by my .xsd grammar I use for validation. The relevant part looks as follows:
<xs:element name="gui">
<xs:complexType>
<xs:sequence>
<xs:element ref="address"/>
<xs:element ref="screenconfig" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="autostart" type="xs:string" use="required"/>
<xs:attribute name="ddocroot" type="xs:string" use="required"/>
<xs:attribute name="listenip" type="xs:string" use="required"/>
<xs:attribute name="listenport" type="xs:string" use="required"/>
<xs:attribute name="prettyname" type="xs:string" use="required"/>
<xs:attribute name="subtype" type="xs:string" use="required"/>
</xs:complexType>
Just in case it's relevant here the initialisation of my parser. It's more or less copied from an example.
XercesDOMParser* parser = new XercesDOMParser();
if (parser->loadGrammar(grammarFilePath.c_str(), Grammar::SchemaGrammarType) == NULL) {
std::cout << "couldn't load schema" << std::endl;
}
parser->setValidationScheme(XercesDOMParser::Val_Always);
parser->setDoNamespaces(true);
parser->setDoSchema(true);
parser->setValidationSchemaFullChecking(true);
parser->setIncludeIgnorableWhitespace(false);
Any idea would be greatly apreciated. If you need any further details, don't hesitate to leave me a comment.
Best, fluorid
Aucun commentaire:
Enregistrer un commentaire