-2

Possible Duplicate:
PHP: Create new XML file and write data to it?
PHP DOM method createElement need to be self-closing tag

i am trying to create a XML file with php, but i don`t know a commmand which creates the following:

<gexf xmlns="http://www.gexf.net/1.2draft" version="1.2">
    <graph mode="static" defaultedgetype="directed">
        <nodes>
            <node id="0" label="Hello" />  //I mena this Object
            <node id="1" label="Word" />
        </nodes>
        <edges>
            <edge id="0" source="0" target="1" />
        </edges>
    </graph>
</gexf>

I'm talking about this child that doesn't consist of one opening statement and a close statement but just a single statement. Now I'm looking for a command that can create this kind of child (<node/>)

4
  • What's your current approach to the problem? :) Commented Jan 2, 2013 at 15:11
  • 2
    There're several built-in libraries to create XML. Care to explain which one you've chosen and what your current code looks like? Commented Jan 2, 2013 at 15:13
  • Simply by using addChild? Im guessing that you use simplexml php.net/manual/en/simplexmlelement.addchild.php Commented Jan 2, 2013 at 15:14
  • 1
    Why do you care if it produces <foo /> or <foo></foo>? They mean the same thing. Commented Jan 2, 2013 at 15:19

1 Answer 1

0

You have two choices.

1 - XML is just a text file. Just create a text file using fopen etc.

Or

2 - Use the DOMDocument model to create the tree structure. You can then use this to create the file from that using the saveXML function.

It is entirely up to you.

Sign up to request clarification or add additional context in comments.

1 Comment

Hello, i dont have a generall problem with creating xml files, i want to produce the element i have marked in the source code with //I mean this object, but i dont even know which name it has so i cant google it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.