I have an XML with the following format:
<dados-cad>
<nome>Wender</nome>
<data>2805094</data>
<code>311</code>
</dados-cad>
How do I in PHP for me to just grab the content that is inside each tags above.
I have an XML with the following format:
<dados-cad>
<nome>Wender</nome>
<data>2805094</data>
<code>311</code>
</dados-cad>
How do I in PHP for me to just grab the content that is inside each tags above.
You can use the php class SimpleXml
.
Here's a simple example of how to use the class.
<?php
$xml = '<dados-cad><nome>Wender</nome><data>2805094</data><code>311</code></dados-cad>';
$simpleXml = simplexml_load_string($xml);
// Acessando os elementos
echo $simpleXml->nome;
echo $simpleXml->data;
More examples of the basic use of this class here .
I know almost nothing about HTML / XML yet.
Could anyone help to make this kind of query up using C #?
I use Visual Studio 2017, I am mounting a client registry in windows-forms.
This time, when the xml has sub-levels, I have difficulty getting the content of the highest / highest level (I do not know the term).
The example below refers to a webservic for cpf query:
<consulta>
<status>1</status>
<return>OK</return>
<result>
<numero_de_cpf>000.000.000-00</numero_de_cpf>
<nome_da_pf>FULANO DE TAL</nome_da_pf>
<data_nascimento>30/12/1981</data_nascimento>
<situacao_cadastral>REGULAR</situacao_cadastral>
<data_inscricao>05/05/2000</data_inscricao>
<digito_verificador>00</digito_verificador>
<comprovante_emitido>9F73.DBF8.4F85.7860</comprovante_emitido>
<comprovante_emitido_data>12:21:27 às 29/08/2017</comprovante_emitido_data>
</result>
</consulta>
What I need is to get the contents of the 'pf_name' tag and play it in a windows-form.
I'm using the code below, but always giving some reference error in xml placement.
private void button1_validar_cpf_Click(object sender, EventArgs e)
{
string urlConsulta = "http://ws.umsitequalquer.com.br/cpf/?xml5&cpf=@cpf&data=@dt_nasc&token=12545269WrhPkfgDHe11972584";
DataSet dsRetornaEndereco = new DataSet();
dsRetornaEndereco.ReadXml(urlConsulta.Replace("@cpf", maskedTextBox1_cpf.Text));
dsRetornaEndereco.ReadXml(urlConsulta.Replace("@dt_nasc", maskedTextBox1_dt_nasc.Text));
string retorno = dsRetornaEndereco.Tables[0].Rows[0]["status"].ToString();
if (retorno == "false")
{
MessageBox.Show(this, "CPF Inválido!", "Validação CPF", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
textBox1_nome.Text = dsRetornaEndereco.Tables[0].Rows[0]["nome_da_pf"].ToString();
}
}
After typing an invalid cpf, all right, the application returns the invalid cpf message, but when I launch a valid cpf, Visual S. says:
Message: Excess No Treatment
System.ArgumentException: 'The column' pf_name 'does not belong to the query table.'
I'm cracking my head rsrsrs
Thanks in advance!
Vlw!