CXmlManager (XML) class?

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

Post Reply
User avatar
BigBang1112
Posts: 389
Joined: 20 Jul 2015, 12:44
Location: Czech Republic
Contact:

CXmlManager (XML) class?

Post 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. :D
Creator and competent racer. YouTube Discord
- ENVIMIX (out in open-source)
- Challenge (OUT NOW)
- Leaderboards (OUT NOW)
- Compute Shadows
User avatar
Dommy
Translator
Translator
Posts: 1901
Joined: 25 Aug 2011, 21:45
Location: Poland
Contact:

Re: CXmlManager (XML) class?

Post 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).
Ryzen 7 2700X, GTX 1070 Ti, 16 GB RAM, Windows 10 Insider Build
FORUM MODERATOR • CREATOR OF SHOOTMANIA GALAXY & TRACKMANIA² PURSUIT

Contact me via GALAXY & PURSUIT DISCORD
User avatar
BigBang1112
Posts: 389
Joined: 20 Jul 2015, 12:44
Location: Czech Republic
Contact:

Re: CXmlManager (XML) class?

Post 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 :D trying to find the usage tho
Creator and competent racer. YouTube Discord
- ENVIMIX (out in open-source)
- Challenge (OUT NOW)
- Leaderboards (OUT NOW)
- Compute Shadows
zocka
Posts: 205
Joined: 15 Jun 2010, 17:56

Re: CXmlManager (XML) class?

Post 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;
}
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka
reaby
Posts: 1032
Joined: 29 Dec 2010, 23:26
Location: Eastern Finland
Contact:

Re: CXmlManager (XML) class?

Post 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
User avatar
Eole
Nadeo
Nadeo
Posts: 1265
Joined: 26 Apr 2011, 21:08

Re: CXmlManager (XML) class?

Post 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);
Contribute to the ManiaPlanet documentation on GitHub
A question about ManiaScript? Ask it here!
User avatar
BigBang1112
Posts: 389
Joined: 20 Jul 2015, 12:44
Location: Czech Republic
Contact:

Re: CXmlManager (XML) class?

Post 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.
Creator and competent racer. YouTube Discord
- ENVIMIX (out in open-source)
- Challenge (OUT NOW)
- Leaderboards (OUT NOW)
- Compute Shadows
zocka
Posts: 205
Joined: 15 Jun 2010, 17:56

Re: CXmlManager (XML) class?

Post 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);
  }
}
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka
User avatar
BigBang1112
Posts: 389
Joined: 20 Jul 2015, 12:44
Location: Czech Republic
Contact:

Re: CXmlManager (XML) class?

Post 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. :D

Thanks for rich answer!
Creator and competent racer. YouTube Discord
- ENVIMIX (out in open-source)
- Challenge (OUT NOW)
- Leaderboards (OUT NOW)
- Compute Shadows
Post Reply

Return to “ManiaScript”

Who is online

Users browsing this forum: No registered users and 0 guests