Ir para conteúdo
Fórum Script Brasil
  • 0

Alterando um xml com prefixo


Frank K Hosaka

Pergunta

XML não é a minha praia, mas encontrei um XML nesse fórum com um monte de prefixos e o membro desse forum perguntou como alterá-lo.

A solução que segue é baseado em improvisação, muitas orientações que eu vi no Google não deram certo, assim eu precisei fazer algumas marteladas. É possível que não funcione com você:

O arquivo 1.xml é esse:

<?xml version="1.0" encoding="UTF-8"?><pt:document xmlns:pt="http://schemas.brother.info/ptouch/2007/lbx/main" xmlns:style="http://schemas.brother.info/ptouch/2007/lbx/style" xmlns:text="http://schemas.brother.info/ptouch/2007/lbx/text" xmlns:draw="http://schemas.brother.info/ptouch/2007/lbx/draw" xmlns:image="http://schemas.brother.info/ptouch/2007/lbx/image" xmlns:barcode="http://schemas.brother.info/ptouch/2007/lbx/barcode" xmlns:database="http://schemas.brother.info/ptouch/2007/lbx/database" xmlns:table="http://schemas.brother.info/ptouch/2007/lbx/table" xmlns:cable="http://schemas.brother.info/ptouch/2007/lbx/cable" version="1.7" generator="P-touch Editor 5.4.007 Windows"><pt:body currentSheet="Folha 1" direction="LTR"><style:sheet name="Folha 1"><style:paper media="0" width="68pt" height="2834.6pt" marginLeft="2pt" marginTop="2.8pt" marginRight="2pt" marginBottom="2.8pt" orientation="portrait" autoLength="true" monochromeDisplay="true" printColorDisplay="false" printColorsID="0" paperColor="#FFFFFF" paperInk="#000000" split="1" format="261" backgroundTheme="0" printerID="28464" printerName="Brother PT-P900W"/><style:cutLine regularCut="0pt" freeCut=""/><style:backGround x="2pt" y="2.8pt" width="64pt" height="66.4pt" brushStyle="NULL" brushId="0" userPattern="NONE" userPatternId="0" color="#000000" printColorNumber="1" backColor="#FFFFFF" backPrintColorNumber="0"/><pt:objects><barcode:barcode><pt:objectStyle x="10pt" y="20.8pt" width="46.4pt" height="46.4pt" backColor="#FFFFFF" backPrintColorNumber="0" ropMode="COPYPEN" angle="0" anchor="TOPLEFT" flip="NONE"><pt:pen style="INSIDEFRAME" widthX="0.5pt" widthY="0.5pt" color="#000000" printColorNumber="1"/><pt:brush style="NULL" color="#000000" printColorNumber="1" id="0"/><pt:expanded objectName="barras" ID="0" lock="0" templateMergeTarget="LABELLIST" templateMergeType="NONE" templateMergeID="0" linkStatus="NONE" linkID="0"/></pt:objectStyle><barcode:barcodeStyle protocol="QRCODE" lengths="48" zeroFill="false" barWidth="1.2pt" barRatio="1:3" humanReadable="true" humanReadableAlignment="LEFT" checkDigit="false" autoLengths="true" margin="true" sameLengthBar="false" bearerBar="false"/><barcode:qrcodeStyle model="2" eccLevel="15%" cellSize="1.6pt" mbcs="auto" joint="1" version="auto"/><pt:data>qrcode de teste</pt:data></barcode:barcode><text:text><pt:objectStyle x="14pt" y="4.8pt" width="38.1pt" height="8.7pt" backColor="#FFFFFF" backPrintColorNumber="0" ropMode="COPYPEN" angle="0" anchor="TOPLEFT" flip="NONE"><pt:pen style="NULL" widthX="0.5pt" widthY="0.5pt" color="#000000" printColorNumber="1"/><pt:brush style="NULL" color="#000000" printColorNumber="1" id="0"/><pt:expanded objectName="modelo" ID="0" lock="0" templateMergeTarget="LABELLIST" templateMergeType="NONE" templateMergeID="0" linkStatus="NONE" linkID="0"/></pt:objectStyle><text:ptFontInfo><text:logFont name="Arial" width="3.4pt" italic="false" weight="400" charSet="0" pitchAndFamily="34"/><text:fontExt effect="NOEFFECT" underline="0" strikeout="0" size="7.8pt" orgSize="28.8pt" textColor="#000000" textPrintColorNumber="1"/></text:ptFontInfo><text:textControl control="FREE" clipFrame="false" aspectNormal="false" shrink="false" autoLF="false" avoidImage="false"/><text:textAlign horizontalAlignment="JUSTIFY" verticalAlignment="CENTER" inLineAlignment="BASELINE"/><text:textStyle vertical="false" nullBlock="false" charSpace="0" lineSpace="0" orgPoint="8pt" combinedChars="false"/><pt:data>ABCDEFG</pt:data><text:stringItem charLen="7"><text:ptFontInfo><text:logFont name="Arial" width="3.4pt" italic="false" weight="400" charSet="0" pitchAndFamily="34"/><text:fontExt effect="NOEFFECT" underline="0" strikeout="0" size="7.8pt" orgSize="28.8pt" textColor="#000000" textPrintColorNumber="1"/></text:ptFontInfo></text:stringItem></text:text><text:text><pt:objectStyle x="14pt" y="12.8pt" width="38.3pt" height="8.7pt" backColor="#FFFFFF" backPrintColorNumber="0" ropMode="COPYPEN" angle="0" anchor="TOPLEFT" flip="NONE"><pt:pen style="NULL" widthX="0.5pt" widthY="0.5pt" color="#000000" printColorNumber="1"/><pt:brush style="NULL" color="#000000" printColorNumber="1" id="0"/><pt:expanded objectName="serie" ID="0" lock="0" templateMergeTarget="LABELLIST" templateMergeType="NONE" templateMergeID="0" linkStatus="NONE" linkID="0"/></pt:objectStyle><text:ptFontInfo><text:logFont name="Arial" width="3.4pt" italic="false" weight="400" charSet="0" pitchAndFamily="34"/><text:fontExt effect="NOEFFECT" underline="0" strikeout="0" size="7.7pt" orgSize="28.8pt" textColor="#000000" textPrintColorNumber="1"/></text:ptFontInfo><text:textControl control="FREE" clipFrame="false" aspectNormal="false" shrink="false" autoLF="false" avoidImage="false"/><text:textAlign horizontalAlignment="JUSTIFY" verticalAlignment="CENTER" inLineAlignment="BASELINE"/><text:textStyle vertical="false" nullBlock="false" charSpace="0" lineSpace="0" orgPoint="8pt" combinedChars="false"/><pt:data>123456789</pt:data><text:stringItem charLen="9"><text:ptFontInfo><text:logFont name="Arial" width="3.4pt" italic="false" weight="400" charSet="0" pitchAndFamily="34"/><text:fontExt effect="NOEFFECT" underline="0" strikeout="0" size="7.7pt" orgSize="28.8pt" textColor="#000000" textPrintColorNumber="1"/></text:ptFontInfo></text:stringItem></text:text></pt:objects></style:sheet></pt:body></pt:document>

A solução que improvisei é esse:

<?php
$dom=new DOMDocument();
$dom->load('1.xml');
$xpath=new DOMXPath($dom);
$elements=$xpath->query("//pt:data");
foreach($elements as $element){echo $element->textContent."<br>";}
foreach($elements as $element){$element->textContent="Frank";}
foreach($elements as $element){echo $element->textContent."<br>";}
// resultado:
qrcode de teste
ABCDEFG
123456789
Frank
Frank
Frank

 

Link para o comentário
Compartilhar em outros sites

0 respostass a esta questão

Posts Recomendados

Até agora não há respostas para essa pergunta

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...