Squirrel/Server/Functions/XmlElement/XmlElement

From Liberty Unleashed Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
(Example)
 
Line 21: Line 21:
 
     local element = XmlElement("Info");
 
     local element = XmlElement("Info");
 
     element.SetAttribute( "Time", GetFullTime() );
 
     element.SetAttribute( "Time", GetFullTime() );
     MyDocument.LinkChild( element );
+
     myDocument.LinkChild( element );
 
     myDocument.SaveFile();
 
     myDocument.SaveFile();
 
}
 
}

Latest revision as of 21:23, 23 August 2016

Home   |   Squirrel Scripting   |   Server Functions   |   Server Events   |   Client Functions   |   Client Events

This function adds a XML Element to the document given.

[edit] Syntax

  1. XmlElement XmlElement( string ElementName )

[edit] Arguments

  • ElementName - The name of the element you wish to add.

[edit] Example

This will load an XML document into the scripts and add an element to it, setting element's attribute to current time.

  1.  
  2. function onScriptLoad()
  3. {
  4. local myDocument = XmlDocument();
  5. myDocument.LoadFile( "Example.xml" );
  6. local element = XmlElement("Info");
  7. element.SetAttribute( "Time", GetFullTime() );
  8. myDocument.LinkChild( element );
  9. myDocument.SaveFile();
  10. }
  11.  

[edit] Output

  1. <Info Time="Wed Jul 03 16:37:54 2013" />

[edit] Notes

The callback onScriptLoad and the functions XmlDocument, XmlDocument.LoadFile, XmlElement.SetAttribute,XmlDocument.SaveFile were used in this example. More info about it is available in the corresponding pages.

[edit] Related Functions

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox