0

I tried this code in PHP;

$oItem->appendChild($oDom->createElement("link", $iItem->item($i)->getElementsByTagName("affiliateUrl")->item(0)->nodeValue));

But it shows error

DOMDocument::createElement(): unterminated entity reference

Is this because of getElementsByTagName contain < > ?

Please advise how to fix it?

That tag is:

<affiliateUrl>http://hb.afl.rakuten.co.jp/hgc/sd0ps992.2asad607.g00ps016.2asfefe9/?pc=http%3A%2F%2Fitem.rakuten.co.jp%2Fmarukans%2Fno11-1%2F&m=http%3A%2F%2Fm.rakuten.co.jp%2Fmarukans%2Fi%2F10000152%2F</affiliateUrl>

Thank you for your help.

chris85
  • 23,846
  • 7
  • 34
  • 51
Kevin Suzuki
  • 25
  • 1
  • 7
  • What does `$iItem->item($i)->getElementsByTagName("affiliateUrl")->item(0)->nodeValue` contain? – chris85 Jul 04 '17 at 02:38
  • It contains URL link. – Kevin Suzuki Jul 04 '17 at 02:46
  • 1
    With a GET parameter in it, `&`? You can probably use `htmlspecialchars` but without knowing the actual string its hard to help. – chris85 Jul 04 '17 at 02:47
  • Thanks. Please see the full code here (http://kumiko-jp.com/archives/32522.html) I guess because getElementsByTagName is trying to get URL link of TAG but it can not get for some reasons..... – Kevin Suzuki Jul 04 '17 at 02:53
  • What is the full tag/content? I think the answer to your question is to use that function on that value. For a detailed explanation on this see https://stackoverflow.com/questions/552957/rationale-behind-simplexmlelements-handling-of-text-values-in-addchild-and-adda. An `&` in XML without an `;` is invalid. – chris85 Jul 04 '17 at 02:58
  • Thanks. the full tag contains http://hb.afl.rakuten.co.jp/hgc/g00ps992.2asad607.g00ps016.2asfefe9/?pc=http%3A%2F%2Fitem.rakuten.co.jp%2Fmarukans%2Fno11-1%2F&m=http%3A%2F%2Fm.rakuten.co.jp%2Fmarukans%2Fi%2F10000152%2F – Kevin Suzuki Jul 04 '17 at 03:10
  • You need to add the code/tag to the question as a code block. – chris85 Jul 04 '17 at 03:11
  • I can not get the affiliateUrl by using getElementsByTagName("affiliateUrl") – Kevin Suzuki Jul 04 '17 at 03:11
  • Thanks. I added to the question – Kevin Suzuki Jul 04 '17 at 03:15
  • You tried the `htmlspecialchars` and it failed? Your `F&m` should break the current XML parser.. It needs to be `F&m` or some entity variation of that. – chris85 Jul 04 '17 at 03:22

1 Answers1

0

To solve the issue : Use the htmlentitites function to convert all applicable characters to HTML entities, htmlentitites = Convert all applicable characters to HTML entities. For example:

$dom->createElement(‘value’, htmlentities($text_value));