0

I want to add two attributes onto an element that looks something like this:

$tutTag->appendChild(
    $xmlDoc->createElement("Port", $serv->STMPPort)
)->setAttribute("type","int")->appendChild->setAttribute("y","l");

In this case, "type" and "int" get added just fine, but the second set "y" and "l" do not get added. How do i fix this?

3
  • I'm not sure but try to remove second ->appendChild witch is reference to probably unknown attribute. Commented Jul 25, 2012 at 16:03
  • if i do: $xmlDoc->createElement("Port", $serv->STMPPort))->setAttribute("type","int")->setAttribute("y","l"); then i get the following error: Call to undefined method DOMAttr::setAttribute() in.. any other ideas? is this what you meant? Commented Jul 25, 2012 at 16:09
  • Could you write down XML you'd like to get as result? Commented Jul 25, 2012 at 16:16

1 Answer 1

1

Maybe you should add it to a variable first.

$childTag = $xmlDoc->createElement("Port", $serv->STMPPort);
$childTag->setAttribute("type","int");
$childTag->setAttribute("y","1");

$tutTag->appendChild($childTag);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.