Manipulating XML after storing String content - PHP

Asked

Viewed 76 times

0

I have a page in PHP and after inserting some information it returns me an XML.

I need to manipulate this XML and show the content along with its tags to the end user, I am storing this content in a string, as code below:

$xml = file_get_contents("http://192.168.10.180/mkl?company=teste&cpf=12345678912");

$arquivo = htmlentities($xml);

print_r ($arquivo);

echo gettype($arquivo);

    <?xml version="1.0"?> <mkl><info><nome>Seu Joao</nome><usuario>mcbt</usuario><password>jkldsajklsdajkashjsa</password></info><found><east><data>1900-01-01</data><mac><testMacRcaess>AA:BB:CC:DD:00:11</testMacRcaess><testestherName>Equipamento</testestherName><testestherManagement>public</testestherManagement><testestherModo></testestherModo><testMACCM>AA:BB:CC:DD:00:11</testMACCM><testBMG>N/A</testBMG><testFormato>Teste_Das</testFormato><testIpDas>true</testIpDas><testestherTechnology> WI-FI 2.0 EBT</testestherTechnology><testvendido>Equip</testvendido><testRcaInterModo>RF</testRcaInterModo><testCasa><testCasa>987654321100</testCasa></testCasa></mac><mac><testMacRcaess>123456789</testMacRcaess><testestherName>920gw</testestherName><testestherManagement>public</testestherManagement><testestherModo> DIGITAL</testestherModo><testMACCM>AA:BB:CC:00:11:22</testMACCM><testBMG>OPTV 1</testBMG><testFormato>Teste_Das</testFormato><testCartao>123456789</testCartao><testIpDas>true</testIpDas><testestherTechnology> DIGITAL OR</testestherTechnology><testvendido>PHILIPS</testvendido><testRcaInterModo>RF</testRcaInterModo><testCasa><testCasa>987654321100</testCasa></testCasa></mac><mac><testMacRcaess>123456789</testMacRcaess><testestherManagement>public</testestherManagement><testestherModo>Cartao</testestherModo><testCasa><testCasa>987654321100</testCasa></testCasa></mac></east><Fast><counter><name>test</name><interval><name>1d</name><limit>0</limit><value>0</value><intervalo>20190101000000</intervalo><testFastLimite>0</testFastLimite><testValor>0</testValor><testFastNextLimite>0</testFastNextLimite><testFastNextLimit>0</testFastNextLimit></interval></counter></Fast><testBirtORay>17-01-1990</testBirtORay><testPhoneNumber>11123456789</testPhoneNumber><testPhoneNumber>11123456789</testPhoneNumber><testCountry>BRASIL</testCountry><testCity>SANTO ANDRE</testCity><testZipCode>09015680</testZipCode><testDocumentId>12345678910</testDocumentId><testEmail>[email protected]</testEmail><testDocModo>CPF</testDocModo><testAccountIds>129155961026</testAccountIds><testAccountIds>1234554321</testAccountIds><testAccountIds>999888777666</testAccountIds><testusuario>mcbtone</testusuario><testUserModo>test</testUserModo><testLoginEmails>[email protected]</testLoginEmails><testPasswordResetEmail>[email protected]</testPasswordResetEmail><testAuthFlag>true</testAuthFlag><testAuthCounter>1</testAuthCounter><testState>SP</testState><testCustomerModo>test-123.com.br</testCustomerModo><testPasswordResetPhoneNumber>11123456789</testPasswordResetPhoneNumber><testjob><testjobID>FAKE</testjobID><testStatus>Fri Jun 07 14:27:29 BRT 2019</testStatus></testjob><testjob><testjobID>123456789</testjobID><testjobModo>INT</testjobModo><testestherID><testestherID>AA:BB:CC:DD:00:11</testestherID></testestherID><testStatus>CONNECTED</testStatus><testRcaessID>123456789</testRcaessID><testRamCode><testRamCode>129</testRamCode></testRamCode><test01><test01>Teste 5M COM TV E FONE FIDELIDADE</test01></test01><test02><test02>10Mb</test02></test02></testjob><testjob><testjobID>FON987654321100</testjobID><testjobModo>FON</testjobModo><testestherID><testestherID>AA:BB:CC:DD:00:11</testestherID></testestherID><testStatus>CONNECTED</testStatus><testRcaessID>123456789</testRcaessID><testRamCode><testRamCode>129</testRamCode></testRamCode><testtestfoneNumber><testtestfoneNumber>+123456789</testtestfoneNumber></testtestfoneNumber><testLacNumber><testLacNumber>11</testLacNumber></testLacNumber><test01><test01>testFONE ILIM BRASIL 123</test01></test01></testjob><testjob><testjobID>PTV987654321100</testjobID><testjobModo>PTV</testjobModo><testestherID><testestherID>123456789</testestherID></testestherID><testStatus>CONNECTED</testStatus><testRcaessID>123456789</testRcaessID><testRamCode><testRamCode>129</testRamCode></testRamCode><testModoVod>TVEverywhere</testModoVod><test01><test01>test TESTE OR 3P FIDELIDADE</test01></test01></testjob><testRcaess><testRcaessID>123456789</testRcaessID><testRcaStreetFull>R TESTE 123 BL 11 APT 841 </testRcaStreetFull><testRcaCity>Teste</testRcaCity><testRcaState>SP</testRcaState><testRcaCountry>BRASIL</testRcaCountry><testRcaZIPCode>09015680</testRcaZIPCode></testRcaess></found><jbl><olca><tvjob><jobID>987654321100</jobID><city>111</city><touchPoint>OR</touchPoint><everywhere>false</everywhere><now>true</now><canais><value>TESTE OR ONLINE</value></canais><canais><value>TESTE SD ONLINE</value></canais><canais><value> GLOBOSAT PLAY MINI BASICO</value></canais><canais><value> CURTA PLAY</value></canais><canais><value> DISCOVERY KIDS PLAY</value></canais><canais><value> MTV PLAY</value></canais><canais><value> 123 DRIVE 25GB</value></canais><canais><value> CINE BR OTT</value></canais><canais><value> CINE EURO OTT</value></canais><canais><value>CONEXAO ONLINE</value></canais><canais><value>TESTE 2013 OR ONLINE</value></canais><canais><value>TESTE 2013 SD ONLINE</value></canais><canais><value> 123VIDEO ONLINE</value></canais><canais><value> HBO BASICO</value></canais><canais><value> MUSIC BOX BRAZIL</value></canais><canais><value> NICK PLAY</value></canais><canais><value> PRIME BOX BRAZIL</value></canais><canais><value> SPACE GO</value></canais><canais><value> SPORTV</value></canais><canais><value> TELECINE</value></canais><canais><value> TNT GO</value></canais><canais><value> TNT SERIES</value></canais><canais><value> TURNER PLAY</value></canais></tvjob><tvjob><jobID>cm-11123456789</jobID><city>50</city><technology>MINHA_123</technology><touchPoint>KEW</touchPoint><now>false</now></tvjob></olca></jbl></mkl> string

As you have noticed, I have no space between the information that is inside the string to perform line break and thus leave the content in a friendly way to see.

  • Take a look at "XML serialization". Should help =)

  • I’ll look vnrs, thank you!

1 answer

0

Use the Domdocument::formatOutput, example:

$dados = file_get_contents("http://192.168.10.180/mkl?company=teste&cpf=12345678912");

if ($dados) {

    $doc = new DOMDocument();

    $doc->formatOutput = true; //Formata de forma amigável a quem vai ler

    $doc->loadXML($dados);

    $xml = htmlentities($doc->saveXML());

    echo $xml;

}

As already explained in Bacco’s reply: /a/140004/3635

  • William, it worked as needed. Thank you very much for your help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.