/    Sign up×
Community /Pin to ProfileBookmark

DOMDocument replace node

Hi!
I need to replace <text:line-break/> tag with empty space
This is my code but something is wrong, can you help me?

<text:index-body>
<text:p text:style-name=”P9″>AAAA
<text:tab/>5</text:p>
<text:p text:style-name=”P9″>
<text:s/>BBB
<text:line-break/>bb1
<text:tab/>6</text:p>
<text:p text:style-name=”P9″>
<text:s/>CCC
<text:line-break/>cc1
<text:tab/>6</text:p>
<text:p text:style-name=”P9″>
<text:index-body/>

$xml=new DOMDocument();
$xml->load($_tmp.”/content.xml”);

$xp= new DOMXPath($xml);

$xquery = “/office:document-content/descendant-or-self::text:index-body”;
$xpic_art= $xp->query($xquery);
for ($k=0; $k<$xpic_art->length; $k++) {
$s=$xpic_art->item($k);

$xpic5=$xp->query(“.//text:line-break”, $s);
if($xpic5->length >0){
$p=$xpic5->item(0);
$p->parentNode->replaceChild(”, $p);
}

}

$content=$xml->saveXML();

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@rootJan 02.2017 — When posting any code, use BBCode tags to wrap code blocks in so they are readable and people are more willing to help, you help yourself by doing so.
Copy linkTweet thisAlerts:
@frangetta83authorJan 02.2017 — This is my code:

[code=html]
<text:index-body>
<text:p text:style-name="P9">AAAA
<text:tab/>5</text:p>
<text:p text:style-name="P9">
<text:s/>BBB
<text:line-break/>bb1
<text:tab/>6</text:p>
<text:p text:style-name="P9">
<text:s/>CCC
<text:line-break/>cc1
<text:tab/>6</text:p>
<text:p text:style-name="P9">
<text:index-body/>
[/code]


[code=php]
$xml=new DOMDocument();
$xml->load($_tmp."/content.xml");

$xp= new DOMXPath($xml);

$xquery = "/office:document-content/descendant-or-self::text:index-body";
$xpic_art= $xp->query($xquery);
for ($k=0; $k<$xpic_art->length; $k++) {
$s=$xpic_art->item($k);

$xpic5=$xp->query(".//text:line-break", $s);
if($xpic5->length >0){
$p=$xpic5->item(0);
$p->parentNode->replaceChild('', $p);
}
}

$content=$xml->saveXML();
[/code]
Copy linkTweet thisAlerts:
@technocratsJan 03.2017 — Code puzzle
×

Success!

Help @frangetta83 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...