Page 1 of 1
CXmlManager (XML) class?
Posted: 02 Mar 2016, 09:34
by BigBang1112
I've seen CXmlManager class in CMlScript called XML. It would be cool to save XML files into media folder with data of choice.
Homever there isnt some kind of Save function there.
So, how is this class useful? I heard that its used in gamemodes.
Thanks for answer.

Re: CXmlManager (XML) class?
Posted: 02 Mar 2016, 11:55
by Dommy
Check the manialink
exchange and press Ctrl + G twice, search for githubusercontent.com or dominolink.aq.pl and see how it's used (a lot).
Re: CXmlManager (XML) class?
Posted: 02 Mar 2016, 14:47
by BigBang1112
domino54 wrote:Check the manialink
exchange and press Ctrl + G twice, search for githubusercontent.com or dominolink.aq.pl and see how it's used (a lot).
i checked it and there is no text after Ctrl+G twice
edit: i understand now

trying to find the usage tho
Re: CXmlManager (XML) class?
Posted: 02 Mar 2016, 16:22
by zocka
In short: you use the CXmlManager to read XML. I don't know if gamemodes can read local XML config files, but other than that it is widely used to read XML from APIs.
When you have a look at the
documentation, you will get how to use it.
Quick example:
Code: Select all
// create document
declare CXmlDocument Document = XML.Create(ApiResponseString);
declare CXmlNode Root = Document.Root;
// iterate over items
declare i = 0;
foreach (Node in Root.Children) {
// Just a little (useless) example on what to do with the data
MyLabels[i].Value = """TagName: {{{Node.Name}}}, Attribute 'data': {{{Node.GetAttributeText("data", "not set")}}}""";
i += 1;
}
Re: CXmlManager (XML) class?
Posted: 02 Mar 2016, 17:18
by reaby
i would use log instead of labels for this example
You might want to check my tutorial about this topic:
viewtopic.php?f=279&t=29396&p=234419#p230480
Re: CXmlManager (XML) class?
Posted: 02 Mar 2016, 19:54
by Eole
zocka wrote:I don't know if gamemodes can read local XML config files
Yes it's possible with the Http API using a file:// address instead of a web url.
Code: Select all
declare Request <=> Http.CreateGet("file://Media/Path/To/My/File.xml", False);
Re: CXmlManager (XML) class?
Posted: 04 Mar 2016, 15:16
by BigBang1112
Code: Select all
declare CXmlDocument xmlFile;
xmlFile.TextContents = Http.CreateGet("file://Media/Path/To/My/File.xml", False).Result;
If I understand this right, these 2 line above will work and read the file as CXmlDocument?
This would be cool to use.
Re: CXmlManager (XML) class?
Posted: 04 Mar 2016, 15:35
by zocka
BigBang1112 wrote:Code: Select all
declare CXmlDocument xmlFile;
xmlFile.TextContents = Http.CreateGet("file://Media/Path/To/My/File.xml", False).Result;
If I understand this right, these 2 line above will work and read the file as CXmlDocument?
Just declaring xmlFile will result in xmlFile being Null and thus not having the property TextContents.
You create CXmlDocument objects with Xml.Create(xmlString).
Http Requests only work asynchronously to my knowledge, so you would need something like shown below, but you can try it
Code: Select all
declare CXmlDocument xmlFile;
...
declare CHttpRequest RequestToLocalFile;
declare Boolean RequestToLocalFilePending;
...
RequestToLocalFile = Http.CreateGet("file://Media/Path/To/My/File.xml", False);
RequestToLocalFilePending = True;
...
while(True) {
yield;
if (RequestToLocalFilePending && RequestToLocalFile.IsCompleted) {
RequestToLocalFilePending = False;
if (RequestToLocalFile.StatusCode == 200) {
xmlFile = Xml.Create(RequestToLocalFile.Result);
doSomethingWithTheData(xmlFile);
} else {
log("probably local file was not found");
}
Http.Destroy(RequestToLocalFile);
}
}
Re: CXmlManager (XML) class?
Posted: 04 Mar 2016, 16:24
by BigBang1112
Oh I see it there.
You need to wait when the file will fully load/download. I want to use it in a titlepack, not default manialink on the internet.
So when reading a file with HttpRequest which isnt on the internet, you will need to wait before it load?
And yeah, I forgot on that Create function.
Thanks for rich answer!