I try to read a value out of an xml-file.
I get the right line into a char[255] using fgets.
When I try to extract the nodes content, the corresponding value doesn't get changed.
XML:
\t<name>A fancy Name</name>
C++:
...
char buff[255];
fgets(buff,255,Filestream);
scanf(buff,"\t<name>%[^<]</name>",&(Daten.name));
Daten.name is an UnicodeString (used by Embarcadero's c++-Builder) by the way.
But Daten.name remains unchanged...
I also tried not using the pointer to Daten.name but the variable directly, but it doesn't seem to change anything...
Can you help me find my mistake here?
Related
A tad confused here, still very much learning obviously.
Running Xcode, with SwiftUI.
I have data which is being read (successfully) from a JSON file, and when I try to use Text() to output an Int, I get the dreaded "No exact matches in call to initialiser' error, yet all of the other items output to the screen perfectly fine.
The data items are declared correctly as either String or Int, but I get this error only when trying to output the Int.
Text(question.question)
Text(question.sylabusItem)
Text(question.correct)
Text(correctAnswer)
Any advice greatly appreciated. Thanks.
Text has quite a lot of initializers. Out of these, one of them accepts a string.
However, none of them accept an Int.
To work around this you can use string concatenation.
Text("\(correctAnswer)") /// assuming correctAnswer is an Int
I have a simple xml file which I need to read in c++. I am working on Windows so I choose MSXML. And it wouldn't be a problem if not for the way of how data is saved in the xml file. I cannot modify files as I have a lot of them + I can get a lot more in future. So the part that interest me the most in the xml file is:
<data>
<sample cost="2.000000000000000e+01">1</sample>
</data>
In the beginning of the xml I have specified a precision of the number and how much digits can be ignored.
So far by doing:
MSXML::IXMLDOMNodeListPtr temp = xmlDoc->selectNodes("data/*");
temp->Getitem(0)->Getxml();
gives me whole line as a string also:
temp->Getitem(0)->Gettext();
gives me a number between sections (in this case it is 1) but as a string. I dont know how to get access to a number in <> without manualy getting it from string returned by Getxml().
Getting this numbers manualy from string and converting them to double and int isnt a problem but I want to know if there is a way to directly get access to this numbers in double and int format.
I have a xml reader in C++ and I am making a error function or proofer that only sends complete xml trees to the parser. The data is in a char array like
char chunkdata[245];
Then convert it to a string like
String data(chunkdata);
And parse the data.
This program will get chunked data at any time and process. The only thing with chunked data is that it sometimes sends incomplete xml trees... So I might only get half of a content in a char array like
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to> Tove</to>
<from>Jani</from>
<heading>Remin
And get a few mil seconds later the rest
der</heading>
<body>Don't forget me this weekend!</body>
</note>
And after processing it would produce two strings and crash the program.
What could I add in my code to either wait to add if not complete... or get only the complete xml trees and leave the remaining to add to the rest when it comes... I tried things like string FIND with string substring which would process then Add the remaining later but it didn't work.. Any suggestions ??? Thank you
If the only thing you're doing is a validator that reads the file in block mode, then you should probably keep track of opened and closed tags in some sort of separate structure. If your buffer can change its length (I'm not sure what String is, but std::string certainly can change its size during runtime), you probably want to have something similar to the following:
std::map<std::string, long> tags;
And when you encounter a tag opening, do:
if(tags.find(tagName))
tags[tagName]++;
else
tags[tagName]=1;
And when you encounter a tag closing, do:
if(tags.find(tagName))
tags[tagName]--;
else
tags[tagName]=-1;
The tags are closed properly only if all the elements of the map are equal 0. Lets assume testForCorrectness() does just that. Then your code would look like this:
char chunkdata[245];
readSomeData();
String data(chunkdata);
while(!testforCorrectness()){
readSomeData();
data += (String)chunkdata;
}
return chunkdata;
If you also want to test if the tags were closed in the correct order - try using a vector instead:
std::vector<std::string> openedTags;
On tag begin:
openedTags.push_back(tagName);
On tag close:
if(openedTags.back() == tagName)
openedTags.pop_back();
else
// XML is ill-formed
Finish if empty(openedTags).
const XMLDataNode *pointsNode = node->GetChildren().at(0);
std::wistringstream pointsstrm(*pointsNode->GetInnerText());
pointsstrm >> loadedGame.points;
This is code I've written to pull an int from an XML file and pass it into loadedGame.points (an int). However, this isn't working. It compiles but doens't give the right value. Why is that? XMLDataNode is a class that manipulates xmllite.dll.
Time for some wild guesses!
I'll bet you that the text you get from *pointsNode->GetInnerText() isn't what you think it is. Have you checked that it is indeed exactly the text you want? In particular, could it contain whitespace? Parsing a nicely formatted (i.e. indented, broken into lines, etc) XML file without a schema to reference ends up meaning that all sorts text nodes involving whitespace will end up in your DOM tree.
I have binary std::string and I need insert it into the BLOB (MySQL) using simple data layer I have. So, I need to execute query: ExecuteSQL((LPTSTR)strQ).
When I am creating this query string (strQ) I cannot add anything to the string after I add this binary string - it just kind if terminated and nothing can be added. I do not want to use mysql_real_escape_string because i want to keep it not only for MySQL.
Anybody to HELP PLEASE!!!
Assuming you have code that looks something like this:
std::string s = ... // populate string somehow
ExecuteSQL( (LPCSTR) s );
Then you have several problems. Forstly, the cast won't work. In C++, whenever you use a cast you are almost certainly doing something incorrect which will break your code. You need to create a null-terminated string using the std::string member function c_str():
ExecuteSQL( s.c_str() );
However, this may not fix all your your problems because you say you hava a binary string. If that string contains the zero byte, then your SQL will terminate at that character rather than the end of string. In that case you probably need to investigate binding your values explicitly.
Edit: For details of how to bind a parameter to a MySQL statement, see http://dev.mysql.com/doc/refman/5.1/en/mysql-stmt-bind-param.html