XmlNodeGetValue: Difference between revisions
Jump to navigation
Jump to search
(→Example: Fixed example using incorrect function) |
No edit summary |
||
Line 1: | Line 1: | ||
{{Server client function}} | |||
__NOTOC__ | __NOTOC__ | ||
This function is made to be able to read values in XML files. | This function is made to be able to read tag values in XML files (eg. <something>anything</something>). | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
string xmlNodeGetValue ( xmlnode | string xmlNodeGetValue ( xmlnode theXMLNode ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*''' | *'''theXMLNode:''' The [[xml node]] of which you need to know the value. | ||
===Returns=== | ===Returns=== | ||
Returns the value of the node if | Returns the value of the node as a [[string]] if it was received successfully, ''false'' otherwise. | ||
==Example== | ==Example== | ||
In this example is | In this example a sample value is returned from a XML file. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local xmlFile=xmlLoadFile(" | local xmlFile = xmlLoadFile ( "exampleFile.xml" ) -- Open a file that we have already created | ||
if xmlFile then --If it's indeed opened | if xmlFile then -- If it's indeed opened | ||
local node = xmlFindSubNode ( xmlFile, "somesubnode", 0 ) -- Find our first sub node | |||
local success = xmlNodeGetValue ( node ) -- Get the value of it | |||
if success then -- Check if it was successful | |||
outputChatBox ( tostring ( success ) ) -- Output "somevalue" to the chatbox | |||
end | |||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
In order for the result to be valid, the xml file has to look like this: | |||
<section name="exampleFile.xml" class="server" show="true"> | |||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
<somenode> | <somenode> | ||
Line 38: | Line 33: | ||
</somenode> | </somenode> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
==See Also== | ==See Also== | ||
{{ | {{XML functions}} | ||
Revision as of 13:58, 26 March 2009
This function is made to be able to read tag values in XML files (eg. <something>anything</something>).
Syntax
string xmlNodeGetValue ( xmlnode theXMLNode )
Required Arguments
- theXMLNode: The xml node of which you need to know the value.
Returns
Returns the value of the node as a string if it was received successfully, false otherwise.
Example
In this example a sample value is returned from a XML file.
local xmlFile = xmlLoadFile ( "exampleFile.xml" ) -- Open a file that we have already created if xmlFile then -- If it's indeed opened local node = xmlFindSubNode ( xmlFile, "somesubnode", 0 ) -- Find our first sub node local success = xmlNodeGetValue ( node ) -- Get the value of it if success then -- Check if it was successful outputChatBox ( tostring ( success ) ) -- Output "somevalue" to the chatbox end end
In order for the result to be valid, the xml file has to look like this:
Click to collapse [-]
exampleFile.xml<somenode> <somesubnode>somevalue</somesubnode> </somenode>
See Also
- xmlCopyFile
- xmlCreateChild
- xmlCreateFile
- xmlDestroyNode
- xmlFindChild
- xmlLoadFile
- xmlLoadString
- xmlNodeGetAttribute
- xmlNodeGetAttributes
- xmlNodeGetChildren
- xmlNodeGetName
- xmlNodeGetParent
- xmlNodeGetValue
- xmlNodeSetAttribute
- xmlNodeSetName
- xmlNodeSetValue
- xmlSaveFile
- xmlUnloadFile