XmlDocument.FirstChild

From Liberty Unleashed Wiki
Jump to: navigation, search
Home   |   Squirrel Scripting   |   Server Functions   |   Server Events   |   Client Functions   |   Client Events

This function gets the first (child) element in an XML document and provides an entry point for traversing the document.

Syntax

  1. XmlElement XmlDocument.FirstChild( )

Arguments

  • None

Example

This is an example XML file:

  1. <TestElement testme="Hello World!" />

This script will load an XML document into the scripts, find the first element in it, and print the text in the attribute "testme."

  1.  
  2. function onScriptLoad()
  3. {
  4. // Load the file itself
  5. local myDocument = XmlDocument();
  6. myDocument.LoadFile( "Example.xml" );
  7.  
  8. // Get the first child
  9. local allMyChildren = myDocument.FirstChild();
  10.  
  11. // Print the text in the attribute
  12. print( allMyChildren.GetAttribute( "testme" ) );
  13. }
  14.  

Notes

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

Related Functions

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox