admin管理员组

文章数量:1313778

Is it acceptable to create your DOMDocument, and then create a number of elements with createElement() and than populate the elements with appendChild in a random order and then when you go to output the document and have everything where it should go, or is the XML buffer in php "building it as you make the calls"?

$xml = new DOMDocument("1.0",'utf-8');
$xml->formatOutput=true;
$rootxml = $xml->createElement("TDNS","root element");
$xml->appendChild($rootxml);

//=====================================================
// IS IT LEGAL TO CREATE SEVERAL ELEMENTS LIKE THIS ALTOGETHER
//=====================================================

$parta=$xml->createElement("astuff");
$partb=$xml->createElement("bstuff");
$partc=$xml->createElement("cstuff");

// and then POPULATE them in any order, like this?

$infoa=$xml->createElement("info_a",$inputa);       // adding to part A
$parta->appendChild($infoa);

$infob=$xml->createElement("info_b",$inputb);       // adding to part A
$parta->appendChild($infob);

$infoc=$xml->createElement("info_c",$inputc);       // adding to part B
$partb->appendChild($infoc);

// THEN MAYBE ADD SOMETHING TO PART C AND THEN A, AND THEN B
//  (you can say why would you do that, but sometimes it is easier to
//   extract data out of a data sort in the order it is provided and
//   assemble it in the correct order on output, it can make the coding
//   much more efficient)

...

// THEN APPEND all the elements into the main XML Document
$xml->appendChild($parta)
$xml->appendChild($partb)
$xml->appendChild($partc)

// THEN PRINT OUTPUT
$xml->saveXML();

Is it acceptable to create your DOMDocument, and then create a number of elements with createElement() and than populate the elements with appendChild in a random order and then when you go to output the document and have everything where it should go, or is the XML buffer in php "building it as you make the calls"?

$xml = new DOMDocument("1.0",'utf-8');
$xml->formatOutput=true;
$rootxml = $xml->createElement("TDNS","root element");
$xml->appendChild($rootxml);

//=====================================================
// IS IT LEGAL TO CREATE SEVERAL ELEMENTS LIKE THIS ALTOGETHER
//=====================================================

$parta=$xml->createElement("astuff");
$partb=$xml->createElement("bstuff");
$partc=$xml->createElement("cstuff");

// and then POPULATE them in any order, like this?

$infoa=$xml->createElement("info_a",$inputa);       // adding to part A
$parta->appendChild($infoa);

$infob=$xml->createElement("info_b",$inputb);       // adding to part A
$parta->appendChild($infob);

$infoc=$xml->createElement("info_c",$inputc);       // adding to part B
$partb->appendChild($infoc);

// THEN MAYBE ADD SOMETHING TO PART C AND THEN A, AND THEN B
//  (you can say why would you do that, but sometimes it is easier to
//   extract data out of a data sort in the order it is provided and
//   assemble it in the correct order on output, it can make the coding
//   much more efficient)

...

// THEN APPEND all the elements into the main XML Document
$xml->appendChild($parta)
$xml->appendChild($partb)
$xml->appendChild($partc)

// THEN PRINT OUTPUT
$xml->saveXML();
Share Improve this question asked Jan 31 at 1:50 TekOpsTekOps 1962 silver badges8 bronze badges 4
  • Is there a reason you can't try the code to see if it works or not? That would be much faster than posting here - in fact, you could have done that in less time than it took you to write your question here. – Ken White Commented Jan 31 at 2:32
  • @KenWhite, I did run the code and it doens't work, that's why I'm asking the question. – TekOps Commented Feb 1 at 1:24
  • That information is not in your question at all. You ask if the functions are "inteilgient [sp]" and "Is it legal?". You do not mention trying to do it or describe any errors you got when you tried to do so. If it isn't in your question, we can't possibly know about it. Keep that in mind in the future - if there's something you want us to know, put it in the question. Sometimes when you don't, your question gets closed. You got lucky that this one hasn't been. – Ken White Commented Feb 1 at 2:37
  • @KenWhite sometimes a person doesn't know how to ask the question the right way. If they did, they might not need to ask the question at all. I was trying to figure out if these functions stored the data intelligently so that you could add data to them in any order and then have them output the result in a cohesive, properly anized format. They do not. I really appreciate your input and I try to be very specific in the questions that I ask. – TekOps Commented Feb 9 at 17:41
Add a comment  | 

1 Answer 1

Reset to default 0

I finally went to OpenAI and discussed the issue with it and it explained that you cannot do things out of order as it will interfere with the nesting it tries to output properly formatted XML.

本文标签: