XmlNodeGetValue: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(→‎Example: Fixed example using incorrect function)
Line 20: Line 20:


==Example==  
==Example==  
In this example is shown what xmlNodeSetValue does and how it works:  
In this example is shown what xmlNodeGetValue does and how it works:  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local xmlFile=xmlLoadFile("xmlfile.xml") --Open a file already created
local xmlFile=xmlLoadFile("xmlfile.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=xmlCreateSubNode(xmlFile,"somesubnode") --Create a new subnode
         local node=xmlFindSubNode(xmlFile,"somesubnode",0) --Find our first subnode
         local success=xmlNodeSetValue(node,"somevalue") --Set 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
                        xmlSaveFile(xmlFile) --Save the file
                    outputChatBox(tostring(success))--Output to the chatbox
                 end --End what still needs to be ended
                 end --End what still needs to be ended
         end
         end
end
end
</syntaxhighlight>
</syntaxhighlight>
The xml file wil look like:  
The xml file will need to look like:  
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<somenode>
<somenode>

Revision as of 10:21, 12 October 2008


This function is made to be able to read values in XML files. (for example <something>anything</something>)

Syntax

string xmlNodeGetValue ( xmlnode xmlnode )             

Required Arguments

  • xmlnode: The node of which you need to know the value.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • none:

Returns

Returns the value of the node if successful, false otherwise.

Example

In this example is shown what xmlNodeGetValue does and how it works:

local xmlFile=xmlLoadFile("xmlfile.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 subnode
        local success=xmlNodeGetValue(node) --Get the value of it
                if success then --Check if it was successful
                    outputChatBox(tostring(success))--Output to the chatbox
                end --End what still needs to be ended
        end
end

The xml file will need to look like:

<somenode>
        <somesubnode>somevalue</somesubnode>
</somenode>

See Also

Template:FunctionArea Functions