How to add a new node in an XML with jQuery?

Question:

How can I add, with jQuery, a new node <nota ordem="4"> with the default nodes that are in the example I'm showing in the XML file below (name,date,unit,reference and text)?

I would like to add an order 4 after the order 3

XML file:

<nota ordem="1">
    <nome>Leonardo</nome>
    <data>07/12/2015</data>
    <unidade>Ensino Médio</unidade>
    <referencia>Este um titulo de conteúdo de teste</referencia>
    <texto>Conteúdo de teste--Conteúdo de teste--Conteúdo de teste--Conteúdo de teste--Conteúdo de teste--Conteúdo de teste.</texto>
</nota>

<nota ordem="2">
    <nome>Marcela</nome>
    <data>08/12/2015</data>
    <unidade>Ensino Médio</unidade>
    <referencia>Este um titulo de conteúdo de teste</referencia>
    <texto>Conteúdo de teste--Conteúdo de teste--Conteúdo de teste--Conteúdo de teste--Conteúdo de teste--Conteúdo de teste.</texto>
</nota>

<nota ordem="3">
    <nome>Rafaela</nome>
    <data>09/12/2015</data>
    <unidade>Ensino Médio</unidade>
    <referencia>Este um titulo de conteúdo de teste</referencia>
    <texto>Conteúdo de teste--Conteúdo de teste--Conteúdo de teste--Conteúdo de teste--Conteúdo de teste--Conteúdo de teste.</texto>
</nota>

NOTE: It's not showing there, but the nodes that have the name of note are surrounded by a node called todas_notas

Answer:

With jQuery you would have to do it like this:

var $node = $('<nota/>', {
    ordem : 4,
    html: [
        $('<nome/>', {html: 'Hugo'}),
        $('<data />', {html: '10/05/2001'}),
        // E assim por diante
    ]
})

As you mentioned that the parent element of your xml is todas_notas , so do it like this:

$('todas_notas').append($node)

So you can see how the node's data nota that it was created, I made a snippet:

$(function(){
    var $node = $('<nota/>', {
	    ordem : 4,
	    html: [
		    $('<nome/>', {html: 'Hugo'}),
		    $('<data />', {html: '10/05/2001'}),
	    ]
    })


    html_of_node = $node.prop('outerHTML');

    $('body').text(html_of_node)
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Scroll to Top