XmlNodeGetValue: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(→‎Example: Fixed example using incorrect function)
No edit summary
Line 1: Line 1:
[[Category:Incomplete]]
{{Server client function}}
 
__NOTOC__  
__NOTOC__  
This function is made to be able to read values in XML files. (for example <something>anything</something>)  
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 xmlnode )             
string xmlNodeGetValue ( xmlnode theXMLNode )             
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''xmlnode:''' The node of which you need to know the value.
*'''theXMLNode:''' The [[xml node]] of which you need to know the value.
 
===Optional Arguments===
{{OptionalArg}}
*'''none:'''


===Returns===
===Returns===
Returns the value of the node if successful, ''false'' otherwise.
Returns the value of the node as a [[string]] if it was received successfully, ''false'' otherwise.


==Example==  
==Example==  
In this example is shown what xmlNodeGetValue does and how it works:
In this example a sample value is returned from a XML file.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local xmlFile=xmlLoadFile("xmlfile.xml") --Open a file that we have already created
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 subnode
    local node = xmlFindSubNode ( xmlFile, "somesubnode", 0 ) -- Find our first sub node
        local success=xmlNodeGetValue(node) --Get the value of it
    local success = xmlNodeGetValue ( node ) -- Get the value of it
                if success then --Check if it was successful
    if success then -- Check if it was successful
                    outputChatBox(tostring(success))--Output to the chatbox
        outputChatBox ( tostring ( success ) ) -- Output "somevalue" to the chatbox
                end --End what still needs to be ended
    end
        end
end
end
</syntaxhighlight>
</syntaxhighlight>
The xml file will need to look like:  
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==
{{FunctionArea_Functions}}
{{XML functions}}
{{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