XML bug

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

XML bug

Post by Midnight »

Ok this has been asked before and I've spent the last few hours searching for the thread that helped explain it however I need your help.

Code: Select all

 
When I read in some XML there are these squares in the XML file that act like the return key and 
                                   seperate lines like this. 
but they are not visual in Irrlicht

well if I edit the XML file with notepad.exe and remove these squares and edit where those squares were with a press of the return key and then load it into Irrlicht there are these solid black lines where the return key was pressed.

At one time I had a fix for this but I don't remember how I did it and if I was forced to copy and paste or what...

So my question is do you know what I'm talking about and how to you get around this problem?
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

I found a way around this.

Crimson Editor

I'm not sure if it was an earlier version or maybe it was that I used an already ruined file but my first attempt at crimson editor produced the same results.

It would appear that notepad doesn't preserve something or another and anyways to make a long story short I can edit with CE without getting those solid blocks.
evo
Posts: 96
Joined: Mon Jun 27, 2005 6:46 pm
Location: The Netherlands

Post by evo »

The squares are probably a <LF> character (=ascii 10).

In a windows text file a normal line end should be a <CR> plus a <LF> character. So ascii 13 + ascii 10.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

uhh what? :?
MikeR
Posts: 767
Joined: Sun Dec 26, 2004 4:03 pm
Location: Northern California USA
Contact:

Post by MikeR »

Just a thought...
When you save your file, is the save option as a txt file? or all files?
It makes a big difference.
If it exists in the real world, it can be created in 3d

Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
evo
Posts: 96
Joined: Mon Jun 27, 2005 6:46 pm
Location: The Netherlands

Post by evo »

uhh what? :?
Sigh ... :wink:

LF = Line feed (send cursor down 1 line)
CR = Carriage return (send cursor to the left)

These are terms from the good old era of the telex machine. Somehow they made it into the ASCII table. And ascii is used on nearly every computer on the planet.
I assume you are familiar with ascii, if not google it up. Basically it is the numerical (byte) value representing a character. For example 'A' has an ascii code 65.

Back to solving the problem. How was the XML file generated. By an editor or with your own code ?
after-life
Posts: 69
Joined: Wed Mar 30, 2005 8:16 am
Location: Keerbergen, Belgium

Post by after-life »

i think its not very smart to use the xml reader/writer for a couple of reasons:

- the file you read has to be xml format
- writing the files seems to be a bitch :p
- its so easy to write your own reader/writer (scroll a bit down to see how)
- its hard to read from the file, every time you read from it you have to know exactly where the code you want is.
-...


Writing your own reader/writer:

I'm not going to explain everything, just the basics, if you want a more advanced explanation, googled it up :D.

The best way to show it is with an example so here we go:

Code: Select all

#include <iostream> //we need this for cout and cerr
#include <string> //we need this to use strings
#include <fstream> //we need this to read from the file

using namespace std;

int main()
{
    string word;  
  //an empty string to put data from the file in

    char filename[] = "config.cfg"; 
  //a string (in the form of a char with an array) with the filename

    string object("bitrate"); 
  //this is the object we are going to search for

    int bitrate; 
/*Here we will store the attribute of the bitrate. Because we know it will be 16, 32 or maybe 64, we use an int. If you want to have a bool, you should use a string and make a little if statement*/
    
    ifstream inputfile(filename); 
  //we declare inputfile so we can then read from it
    
    if(!inputfile.is_open()) //we check if inputfile is open
    {
        cerr<<"ERROR; Couldn't open "<< filename <<endl;  
  //if its not open we show an error

        system("pause");
  //pause it so people can read it

        exit(1); 
  //and exit
    }
    
/*now we make a while loop so that it inputs a word into our string: word. Every time it does the while loop, it enters the next word into our string starting with the first word if the word is the object we are looking for, we exit the file.*/
    
    while(word != object) 
    {
        inputfile >> word; 
    }
    
    inputfile >> word; 
  //now we just need to load in the attribute, which is the next word

    cout << word <<endl; 
  //for the sake of this example, we output it to the screen
    
    system("pause");
    return 0;
}

Now, here is my config.cfg file :

Code: Select all

driver opengl
resX 1024
resY 768
bitrate 32
fullscreen true
as you can see, easy to write and easy to read.
all you have to do is make it into a class and enjoy :D

btw, if you want to write from a file, you can use ofstream instead of ifstream and then do outputfile<<word;
so you just add word to the outputfile.
Good luck and have fun with it :D

You will never have does XML bugs, ever!!!
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

The reason I'm using XML is because there is a XMLGUI reader somewhere on the forums it is one format I want to output to.

Also I don't think what I need works as well like that but maybe I'm wrong.

Currently I use a system simular to that for outputting to text as a save file.

But is it capable of handling the element list in Guice and quickly switching it's order? how about undo and redo functions? can you save a crap load of data at the same time very quickly without a lot of errors?

I know with my current save function it crashes the program if you save to much at once but that might be an overflow bug for the string that holds it.

Besides I don't need to manually edit a lot of XML and crimson editor seems to do a great job if I start with a normal file.
after-life
Posts: 69
Joined: Wed Mar 30, 2005 8:16 am
Location: Keerbergen, Belgium

Post by after-life »

what i explained here was just a basic function, you can make a nice class out of it if you want, it can be very powerfull.

But if you prefer to use another reader, that is realy ok with me.
It's just that i like to make my own stuff or at least adapt the stuff others made so it fits my needs perfectly :D
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

XML fits my needs perfectly.

So it should make perfect sense.. shouldn't it? 8)


My friend Electron hooked me up with XML to string.. I know you can do it without XML however I don't need to make my own class at all with XML it integrates perfectly with my existing project and it allows me to write and XML file which works with the already written XML gui loader floating on the boards.

This is why it fits my needs.. and I'm more familiar with it then your example.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

Now I'm getting the boxes when i use my writer to string class.

I'm printing it to the console in Guice and i use \n to end the line in the string.

Anyone know if there is another way to write a line break in an xml file?
dhenton9000
Posts: 395
Joined: Fri Apr 08, 2005 8:46 pm

Post by dhenton9000 »

see if there is cdata support in the parser

http://www.w3schools.com/xml/xml_cdata.asp

cdata elements in xml allow for white space.

HTH
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

I'm not about to start altering Irrlicht XML classes...

why don't you fix it since you know so much about the subject.

I'm really gtting tired of having to rewrite everything in this engine I mean seriously wtf.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

this is a cross platform problem with \n. Windows uses CRLF. Unix LF and Macintosh CR.
anyway, partly human error: in notepad one of them is invisible while the other one shows up as a square, then you delete the visible half and replace it with a CRLF, and the invisible one is still there, so it ends up with CRCRLF, which in windows means "CR\n" and in unix "CRCR\n"... or the other way round i dunno- damn awkward anyway
my advice is to strip both cr and lf from your strings and not use \n at all in your data, use "!!RETURN!!" or something if you really want to store returns.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

Ok how can I make that work in a string though?

I tried it and I'm getting like 5 errors because of the "!!RETURN!!" specific commands.

"!!RETURN!!" how much of that do I actually need? do I need quotations? what about the exclimations? what type of code is this anyways?

::::::::EDIT::::::::
Ok anyways I tried this \"\!\!RETURN\!\!\"

and this \!\!RETURN\!\!

but all that does is print it to the file/string.. I don't want it printed to the file/string unless it is only going to give me an actual return without the black box bug.

I'll try saving it to an actual file and reading it from there.
Post Reply