[ISE] XML scanning

Forum van 1ste Bachelor Informatica.

Moderator: Praesidium

User avatar
Flipper
Posts: 193

[ISE] XML scanning

Post#1 » Sun Feb 17, 2013 5:48 pm

Voor inleiding software engineering moeten we wat vertrouwd geraken met de xml-parser, nu heb ik daar even een klein probleempje: ik probeer namelijk de xml-file te scannen op een specifieke node, maar in plaats van de hele file door te scannen, heb ik de indruk dat er gescand wordt tot de 1e verschijning van de gezochte node:

Mijn code voor scanning:

Code: Select all


std::cout << "All floats found: " << std::endl;
for (TiXmlElement* node=root->FirstChildElement("float"); node != NULL; node->NextSiblingElement("float") ) {
if (node->Attribute("value") != NULL) {
std::cout << node->Attribute("value") << std::endl;
}
continue;
}
Mijn xml file:

Code: Select all


<?xml version"1.0" ?>
<root>
<ignore value="Hello World!" />
<float value=42.0/>
<ignore />
<float value=42.1/>
<float value=42.2/>
</root>
En genereert als output:

Code: Select all


All floats found:
42.0
En ik wilde eigenlijk:

Code: Select all


All floats found:
42.0
42.1
42.2
Iemand een idee?
:|
They call him Flipper, Flipper, faster than lightning,
No-one you see, is smarter than he,
And we know Flipper, lives in a world full of wonder,
Flying there-under, under the sea!

User avatar
Flipper
Posts: 193

Re: [ISE] XML scanning

Post#2 » Sun Feb 17, 2013 6:00 pm

Ah nvm, found it out why :idea: :facepalm:
They call him Flipper, Flipper, faster than lightning,
No-one you see, is smarter than he,
And we know Flipper, lives in a world full of wonder,
Flying there-under, under the sea!

User avatar
Robbe
WOZ
Posts: 2161
Contact:

Re: [ISE] XML scanning

Post#3 » Mon Feb 18, 2013 1:01 am

Flipper wrote:Ah nvm, found it out why :idea: :facepalm:
Care to share with the rest of the world? Niets erger dan EXACT uw probleem te vinden en dan die post tegen te komen...
"I'm not afraid of falling, I'm afraid of landing" -- Sam
How To Ask Questions The Smart Way

Zingen? UKA-n dat ook!

User avatar
Fristi
WOZ
Posts: 4565

Re: [ISE] XML scanning

Post#4 » Mon Feb 18, 2013 1:30 am

Image
Fristi Ad Infinitum

WINAK WOZ 2013 - ...
WINAK Magister Fristi 2012-2013
WINAK Feest 2011-2012
WINAK Schachtentemmer 2010-2011
WINAK Scriptor 2008-2009 | 2009-2010

JR
Posts: 23

Re: [ISE] XML scanning

Post#5 » Wed Feb 20, 2013 3:13 pm

Die continue; als laatste statement in de for vind ik wel intrigerend

User avatar
Flipper
Posts: 193

Re: [ISE] XML scanning

Post#6 » Wed Feb 20, 2013 4:34 pm

Robbe wrote:
Flipper wrote:Ah nvm, found it out why :idea: :facepalm:
Care to share with the rest of the world? Niets erger dan EXACT uw probleem te vinden en dan die post tegen te komen...
Fristi wrote:Image
Haha, oeps :P

Nee, het stomme is dat de code die ik in het begin van dit topic heb aangegeven, volledig correct is, deze werkt dus wel degelijk. De code waar ik wel een probleem mee had was:

Code: Select all


std::cout << "All floats found: " << std::endl;
for (TiXmlElement* node=root->FirstChildElement("float"); node != NULL; node->NextSibling("float") ) {
if (node->Attribute("value") != NULL) {
std::cout << node->Attribute("value") << std::endl;
}
continue;
}
Het zat em in de state-update wanneer de for-body is uitgevoerd: hierboven schreef ik dus

Code: Select all

node->NextSibling("float")
in plaats van de juiste:

Code: Select all

node->NextSiblingElement
Wat verder bleek dat TiXmlElement een derived class was van TiXmlNode, waardoor de compiler geen problemen had met compilen.

strange, u code goed typen op het forum, maar niet in u prog zelf.. :facepalm:
JR wrote:Die continue; als laatste statement in de for vind ik wel intrigerend
Hoezo?
They call him Flipper, Flipper, faster than lightning,
No-one you see, is smarter than he,
And we know Flipper, lives in a world full of wonder,
Flying there-under, under the sea!

User avatar
Flipper
Posts: 193

Re: [ISE] XML scanning

Post#7 » Wed Feb 20, 2013 4:40 pm

Oh en ik had ook problemen met het doorzoeken in text nodes, volgens de website zou je daarvoor de functie

Code: Select all

node->ToText()
zijn, dit is volgens mij echter een foutje, want bij mij werkt dat totaal niet, wat bij mij wel werkte was

Code: Select all

node->getText()
geen idee of dat bij iemand anders ook zo is, of doe ik iets verkeerd? :?
They call him Flipper, Flipper, faster than lightning,
No-one you see, is smarter than he,
And we know Flipper, lives in a world full of wonder,
Flying there-under, under the sea!

User avatar
djgl3nn
WOZ
Posts: 1938

Re: [ISE] XML scanning

Post#8 » Thu Feb 21, 2013 5:05 pm

Flipper wrote:
JR wrote:Die continue; als laatste statement in de for vind ik wel intrigerend
Hoezo?
Wat is het nut van die continue ?
WINAK Schacht 2009-2010
WINAK Sport 2010-2011
WINAK Mentor Informatica 2011-2012
WINAK Ouwe Zak 2012-...

UA Sportraad Webmaster 2012-...

User avatar
Joachimvdh
Prosenior
Posts: 1092

Re: [ISE] XML scanning

Post#9 » Thu Feb 21, 2013 6:10 pm

uw loop herhaalt zich ook zonder continue hoor :p

User avatar
Flipper
Posts: 193

Re: [ISE] XML scanning

Post#10 » Fri Feb 22, 2013 10:10 am

hmm, gewoonte van me om die continue steeds op te zetten, moet ik toch eens afleren :P
They call him Flipper, Flipper, faster than lightning,
No-one you see, is smarter than he,
And we know Flipper, lives in a world full of wonder,
Flying there-under, under the sea!

Return to “1ste Bachelor”

Who is online

Users browsing this forum: No registered users and 8 guests