template< typename char_type >
class IIrrXMLWriter: public whatever
{
public:
virtual const char_type* writeElement( const char_type* name, bool empty, bool holdForAttributes );
virtual const char_type* writeAttribute( const char_type* name, const char_type* value);
virtual const char_type* closeElement();
};
int main()
{
IIrrXMLWriter* xml = create xml writer;
// write the header, the function writeXMLHeader probably doesn,t need XML in its name
xml->writeHeader();
xml->writeElement("letter",true,true); // its empty, but don't close because we have to write attributes
xml->writeAttribute("name","Joe");
xml->writeAttribute("address","no where");
xml->closeElement(); // no need to supply name, it internally figures it out using possibly a stack
// what if nested elements need to be written
xml->writeElement("letter",false,true); // its not empty, but don't close because we have to write attributes
xml->writeAttribute("name","Joe");
xml->writeAttribute("address","no where");
xml->writeElement("body",false,false); // auto write the /> characters to close element letter opening tag
xml->writeText("Hello, how are you. I am trying to improve Irrlicht. Its a great engine. You should check it out. Love Always, Irrlicht");
xml->closeElement(); // close body
xml->closeElement(); // close leter
return 0;
}
<?xml version="1.0"?>
<body
mass = "1000.0"
width = "1.83"
height = "0.963"
depth = "4.470"
model = "chassis.obj"
vshader = "vert.glsl"
fshader = "frag.glsl"
wind_sound = "sound/windy.wav"
/>
<?xml version="1.0"?>
<body>
<mass>1000.0</mass>
<width>1.83</width>
<height>0.963</height>
<depth>4.470</depth>
<model>chassis.obj</model>
<vshader>vert.glsl</vshader>
<fshader>frag.glsl</fshader>
<wind_sound>sound/windy.wav</wind_sound>
</body>
<int name="VariableNameInt" value="152722522" />
<float name="VariableNameFloat" value="1.000000" />
<string name="VariableNameString" value="one" />
The attributes interface is about serialization
So each attribute saves name, value and type. If that last one is needed depends a little bit on what you do - actually in many cases it wouldn't be necessary
But I think it's used for example in irrEdit to allow support for editing parameters without irrEdit having to know _which_ parameters an interface supports.
clarks wrote:What if we could control how IAttributes are read and written. How about specifying whether or not it should write as an attribute element or as real xml attributes. A same way for reading them as attribute elements or as real xml attributes. I am thinking in terms of making it a bit more general purpose, but I could be pushing this to far.
<attributes>
VariableNameInt="152722522"
VariableNameFloat ="1.000000"
VariableNameString = "one"
</attributes>
core::stringw xmldata::winconvert(core::stringw str)
// Convert accents from loaded XML files (irrXML)
// WARNING: Tested only on windows
// might not work on Linux or other platform.
{
bool debug = false;
core::stringw textline = L"";
core::stringw text = L"";
u32 base = 0;
char test2 = ' ';
for (u32 a=0; a<str.size(); a++)
{
// Get the character first
text = str.subString(a,1);
// Then check this character directly (convert to unsigned 32bit)
base=(u32)text[0];
if (base<256) // Standard characters
{
textline+=text;
}
// All characters after 256 are ignored except thoses
// Character higher are re-aligned from the offset to match LATIN1
// Reference to the table is here:
// http://www.utf8-chartable.de/unicode-utf8-table.pl
const u32 offset=65216;
core::stringw replace = L" ";
if ((base>255) && ((base-offset)<255))
{
replace[0]=(base-offset);
textline+=replace;
}
}
return textline;
}clarks wrote:The one im thinking about is like a fixed pipeline, thats probably templated;
- cpp Code: Select all
template< typename char_type >
class IIrrXMLWriter: public whatever
{
public:
virtual const char_type* writeElement( const char_type* name, bool empty, bool holdForAttributes );
virtual const char_type* writeAttribute( const char_type* name, const char_type* value);
virtual const char_type* closeElement();
};
int main()
{
IIrrXMLWriter* xml = create xml writer;
// write the header, the function writeXMLHeader probably doesn,t need XML in its name
xml->writeHeader();
xml->writeElement("letter",true,true); // its empty, but don't close because we have to write attributes
xml->writeAttribute("name","Joe");
xml->writeAttribute("address","no where");
xml->closeElement(); // no need to supply name, it internally figures it out using possibly a stack
// what if nested elements need to be written
xml->writeElement("letter",false,true); // its not empty, but don't close because we have to write attributes
xml->writeAttribute("name","Joe");
xml->writeAttribute("address","no where");
xml->writeElement("body",false,false); // auto write the /> characters to close element letter opening tag
xml->writeText("Hello, how are you. I am trying to improve Irrlicht. Its a great engine. You should check it out. Love Always, Irrlicht");
xml->closeElement(); // close body
xml->closeElement(); // close leter
return 0;
}
An interesting thing is that to write elements there are two functions in the original interface. One takes an array of names and values using wchar_t, while the other takes alot of parameters. Then there is the IAttribute class that is very flexible but there is some inconsistency. I believe that the way that these two interfaces writes attributes should be the same. However, IAttributes are writing attributes as elements, but the xml writer writes attributes:
<body what="this is how attributes should be written"/>
I was reading an article about xml at http://www.w3schools.com/ where the author rejected the idea of using attributes. Now personally I am not a big fan of xml, but Irrlicht is great. So if irrlicht provides I use. Now take a look at this xml doc:
- cpp Code: Select all
<?xml version="1.0"?>
<body
mass = "1000.0"
width = "1.83"
height = "0.963"
depth = "4.470"
model = "chassis.obj"
vshader = "vert.glsl"
fshader = "frag.glsl"
wind_sound = "sound/windy.wav"
/>
vs.
- cpp Code: Select all
<?xml version="1.0"?>
<body>
<mass>1000.0</mass>
<width>1.83</width>
<height>0.963</height>
<depth>4.470</depth>
<model>chassis.obj</model>
<vshader>vert.glsl</vshader>
<fshader>frag.glsl</fshader>
<wind_sound>sound/windy.wav</wind_sound>
</body>
This first doc is easy to read and pretty straight forward. Now imagine if these attributes were written as elements (the second doc), it would be overkill. Now some people would actually prefer that. Why on the earth would they prefer that I don't know. But I am a big fan of keeping things simple and clean. If xml writer can take an array of names and values, it probably should be able to return one. IAttributes is powerful but attributes are really elements. Irrlicht gets better every day, and as it continues to mature I think we should keep it clean.
The reason why data should NOT be stored in attributes is because of data types.
Return to Open Discussion and Dev Announcements
Users browsing this forum: chronologicaldot and 1 guest