I need to pass parameters to my xml nodes like
<NewsService FormalName="Feed" link-url="http://www.tv.com/">http://www.tv.com/img/UTv.jpg</NewsService>

here newsservice is my node and FormalName and link-url are my parameters.
Below specified is my code .There i have read a rss feed and converted that data to xml besides i have added some information from my database to these xml file.My prblem is ,i need to add some parametr values to my xml nodes.

$homepage = file_get_contents('http://www.horas.com/feed/');
$homepage = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $homepage);
$xml = simplexml_load_string($homepage,'SimpleXMLElement', LIBXML_NOCDATA);
$details=$xml->channel;

    $doc = new DOMDocument('1.0','UTF-8');
    $doc->formatOutput = true;
    $r = $doc->createElement( "channel" );
    $doc->appendChild( $r );
    $b = $doc->createElement( "info" );

        $title1= $doc->createElement( "title" );
        $title1->appendChild($doc->createTextNode($details->title));
        $b->appendChild( $title1);

        $comments1 = $doc->createElement( "description" );
        $comments1 ->appendChild($doc->createTextNode($details->description));
        $b->appendChild( $comments1  );

        $lastBuildDate = $doc->createElement( "lastBuildDate" );
        $lastBuildDate->appendChild($doc->createTextNode($details->lastBuildDate));
        $b->appendChild( $lastBuildDate);

        $language = $doc->createElement( "language" );
        $language->appendChild($doc->createTextNode($details->lastBuildDate));
        $b->appendChild( $language);

        $syupdatePeriod1 = $doc->createElement("syupdatePeriod");
        $syupdatePeriod1->appendChild($doc->createTextNode($details->syupdatePeriod));
        $b->appendChild( $syupdatePeriod1);

        $generator = $doc->createElement( "generator" );
        $generator->appendChild($doc->createTextNode($details->generator));
        $b->appendChild( $generator);



        $details1=(array) $opt->category;
        $category = $doc->createElement( "category" );
        $category->appendChild($doc->createTextNode( $details1[0] ));
        $b->appendChild( $category);


        $contentencoded = $doc->createElement( "contentencoded" );
        $contentencoded->appendChild($doc->createTextNode( $opt->contentencoded ));
        $b->appendChild( $contentencoded);

        $wfwcommentRss = $doc->createElement( "wfwcommentRss" );
        $wfwcommentRss ->appendChild($doc->createTextNode( $opt->wfwcommentRss ));
        $b->appendChild( $wfwcommentRss);


        $slashcomments= $doc->createElement( "slashcomments" );
        $slashcomments->appendChild($doc->createTextNode( $opt->slashcomments ));
        $b->appendChild( $slashcomments);
        $r->appendChild( $b );


    }

$doc->save("horasxml.xml")

but with title i need to pass the parametr category="book" author="ramk"

ie <title category="book" author="ramk">

how will i do it please help me

You'll want to create the attributes against the DOMDocument object. This is done with the DOMDocument::createAttribute method.

$cat = $doc->createAttribute ('category');
$author = $doc->createAttribute ('author');

$cat->value = 'book';
$author->value = 'ramk';

$title1->appendChild ($cat);
$title1->appendChild ($author);

What's happening is a DOMAttr object is being instantiated for each attribute you'll utilize. You then set the value property of each attribute, as necessary, and append it to the element you want it applied to.

I can't seem to edit my post, but I did want to mention one other thing:

The value can be set via the DOMAttr's constructor. Afterwards you can then directly access the value property to change it, if need be.

Example of setting value via constructor
$attr = $domDoc->createAttribute ('name', 'my value');

Thank you very much BHensley.It worked for me and it solved my problem>Thank uuuuuuuu

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.