Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 17th, 2007, 08:40 AM
Authorized User
 
Join Date: Feb 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to authenticate (login) from xml file

 Hi experts....

I m beginner in using xml through php. I have user id(emial id) and password in xml file from where I have to authenticate for login users.
The xml file is:
//*************** passwd.xml ***************

<?xml version="1.0"?>
<ieee>
<tgroup>
<email>[email protected]</email>
<password>khuranaraaj</password>
</tgroup>
</ieee>

I want to match this email id and password from this file by using php4.2. So kindly illustrate it through example..

Thank you very much in advance........



 
Old December 17th, 2007, 08:47 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Posting exactly the same question twice will not get your question answered. This might be because:

a) No one knows the answer, or
b) You haven't provided enough information for us to work out what the problem is.
c) You asked for us to do all the work for you without showing what you've tried already.

Do a google search for php and xml and see if you can come up with anything, try a few things, and if you find something you think should work but can't get it to then come back with a question.

Alternatively try posting on a php forum where you might get a better response.

/- Sam Judson : Wrox Technical Editor -/
 
Old December 26th, 2007, 10:00 AM
Authorized User
 
Join Date: Feb 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by samjudson
 Posting exactly the same question twice will not get your question answered. This might be because:

a) No one knows the answer, or
b) You haven't provided enough information for us to work out what the problem is.
c) You asked for us to do all the work for you without showing what you've tried already.

Do a google search for php and xml and see if you can come up with anything, try a few things, and if you find something you think should work but can't get it to then come back with a question.

Alternatively try posting on a php forum where you might get a better response.

/- Sam Judson : Wrox Technical Editor -/
We..l..well thanx to reply me......
My problem has been sort outed but one addition change is needed.
Actully, I have to read and display its contents of a xml file named as pendingnews.xml, given below


//************* pendingnews.xml *****************

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE lotr_characters [
<!ELEMENT person (name , email , newstitle , description)>
<!ATTLIST person alignment (good | evil) #REQUIRED>
<!ELEMENT name (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT newstitle (#PCDATA)>
<!ELEMENT description (#PCDATA)>
]>

        <ieee>
        <tgroup>
                <person alignment="good">
                <name>Raaj</name>
                <email>[email protected]</email>
                <newstitle>u can post news now</newstitle>
                <description>U can post news now..</description>
                </person>

                <person alignment="evil">
                <name>Deep</name>
                <email>[email protected]</email>
                <newstitle>Easy tool for u</newstitle>
                <description>There r ur desired tools available on net.</description>
                </person>

                <person alignment="good">
                <name>Pankaj: The Bhangra Guru</name>
                <email>[email protected]</email>
                <newstitle>Bhangra in IITK</newstitle>
                <description>There will bhagra dance in iitk on occasion of Antaragani</description>
                </person>

         </tgroup>
         </ieee>

//************************************************** ***********

I write this file by using php code shown below

//*************** lnewspost.php **********************

<?
 $post=$_POST['post'];
 $news_msg='';
 $xml='./doc/xml/pendingnews.xml';
 if($post)
   {
    if (version_compare(PHP_VERSION,'5','>='))
    require_once('domxml-php4-to-php5.php');
    //the folowing cotents are posted by GUI having field names
    //name,email..etc

    $name =$_POST['name'];
    $email =$_POST['email'];
    $newstitle =$_POST['newstitle'];
    $description =$_POST['description'];

    if(($email=='')|| ($newstitle=='')|| ($describe==''))
      {
       $tag=array(name, email, newstitle, description);
       $tagval=array($name, $email, $newstitle, $description);
       if(file_exists($xml))
         {
          if ($dom=domxml_open_file("$xml"))
             {
              $root=$dom->document_element();
              $bs=$root->get_elements_by_tagname('tgroup');
              if (count($bs)==1)
                 {
                  $totarr=count($tag);
                  $body=$bs[0];

for($r=0; $r<$totarr; $r++)
    {
    $body=$bs[0];
    $k=$dom->create_element($tag[$r]);
    $k->append_child($dom->create_text_node($tagval[$r]));
    $body->append_child($k);
    $body->append_child($dom->create_text_node("\n"));
    } //end of for $body->append_child($dom->create_text_node("\n"));
  } //end of 5th inner most "if"

  $dom->dump_file("$xml",false,false);
  $news_msg="Congratulations..! News has posted successfully";
  header("location: newspost.php?newsmsg=$news_msg");
  exit;
  } //end of 4th inner "if"
else
  {
   $news_msg="Sorry..! News file could not opend";
   header("location: newspost.php?newsmsg=$news_msg");
   }
 } //end of 3rd inner "if"
 else
   {
   $news_msg="File does not exists or write permission denied";
   header("location: newspost.php?newsmsg=$news_msg");
   }

} //end of 2nd inner "if"

}//end of 1st inner "if"
?>
//************************************************** ************


I had display the xml file (pendingnews.xml) by following code
//*********************** readnews.php *****************

<?
if( ! ($fp = fopen( "./doc/xml/pendingnews.xml" , "r" )) )
                die("Couldn't open xml file!");
                $person_counter = 0;
                $person_data = array();
                $xml_current_tag_state = '';

        function startElementHandler( $parser, $element_name, $element_attribs )
                {
                global $person_counter;
                global $person_data;
                global $xml_current_tag_state;
                if( $element_name == "PERSON" )
                        {
                        $person_data[$person_counter]["alignment"] = $element_attribs["ALIGNMENT"];
                        }
                else
                        {
                        $xml_current_tag_state = $element_name;
                        }
                }

        function endElementHandler( $parser, $element_name )
                {
                global $person_counter;
                global $person_data;
                global $xml_current_tag_state;
                $xml_current_tag_state = '';
                if( $element_name == "PERSON" )
                        {
                        $person_counter++;
                        }
                }

function characterDataHandler( $parser , $data )
                {
                global $person_counter;
                global $person_data;
                global $xml_current_tag_state;
                if( $xml_current_tag_state == '' )
                return;

                if( $xml_current_tag_state == "NAME" )
                        {
                        $person_data[$person_counter]["name"] = $data;
                        }

                if( $xml_current_tag_state == "EMAIL" )
                        {
                        $person_data[$person_counter]["email"] = $data;
                        }

                if( $xml_current_tag_state == "NEWSTITLE" )
                        {
                        $person_data[$person_counter]["newstitle"] = $data;
                        }

                if( $xml_current_tag_state == "DESCRIPTION" )
                        {
                        $person_data[$person_counter]["description"] = $data;
                        }
                }

 if( !($xml_parser = xml_parser_create()) )
                die("Couldn't create XML parser!");
                xml_set_element_handler($xml_parser, "startElementHandler", "endElementHandler");
                xml_set_character_data_handler($xml_parser, "characterDataHandler");
                while( $data = fread($fp, 4096) )
                        {
                        if( !xml_parse($xml_parser, $data, feof($fp)) )
                                {
                                break; // get out of while loop if we're done with the file
                                }
                        }

                xml_parser_free($xml_parser);
?>

        <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
        <html>
        <head>
        <title>Parsing the Sample XML File</title>
        </head>
        <body bgcolor="#ffffff">
        <?
                //echo$person_counter;
                for( $i=0 ; $i < $person_counter ; ++$i )
                //for( $i=0 ; $i < 5; ++$i )
                        {
                        $font_color = $person_data[$i]["alignment"] == "good" ? "#0000ff" : "#ff0000";
                        echo "" .
                        $person_data[$i]["name"] . "<br>\n";
                        echo "Email: &nbsp;&nbsp;" . $person_data[$i]["email"] . "<br>\n";
                        echo "News Title: &nbsp;&nbsp;" . $person_data[$i]["newstitle"] . "<br>\n";
                        echo "News Desc: &nbsp;&nbsp;" . $person_data[$i]["description"] . "<br>\n";
                        echo "<br>\n";
                        }
        ?>
        </body>
 if( !($xml_parser = xml_parser_create()) )
                die("Couldn't create XML parser!");
                xml_set_element_handler($xml_parser, "startElementHandler", "endElementHandler");
                xml_set_character_data_handler($xml_parser, "characterDataHandler");
                while( $data = fread($fp, 4096) )
                        {
                        if( !xml_parse($xml_parser, $data, feof($fp)) )
                                {
                                break; // get out of while loop if we're done with the file
                                }
                        }

                xml_parser_free($xml_parser);
?>

        <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
        <html>
        <head>
        <title>Parsing the Sample XML File</title>
        </head>
        <body bgcolor="#ffffff">
        <?
                //echo$person_counter;
                for( $i=0 ; $i < $person_counter ; ++$i )
                //for( $i=0 ; $i < 5; ++$i )
                        {
                        $font_color = $person_data[$i]["alignment"] == "good" ? "#0000ff" : "#ff0000";
                        echo "" .
                        $person_data[$i]["name"] . "<br>\n";
                        echo "Email: &nbsp;&nbsp;" . $person_data[$i]["email"] . "<br>\n";
                        echo "News Title: &nbsp;&nbsp;" . $person_data[$i]["newstitle"] . "<br>\n";
                        echo "News Desc: &nbsp;&nbsp;" . $person_data[$i]["description"] . "<br>\n";
                        echo "<br>\n";
                        }
        ?>
        </body>
        </html>



//************************************************** *******
My code in lnewspost.php is not writing the following 2 lines in xml file pendingnews.xml

 <person alignment="good"> //in the begning of block

 </person> //in the end of the block


My First question is how to write these line at right location ?(through php code in lnewspost.php) note that I wrote it manually


My second question is, How I can delete any perticular block / blocks (starting with <person alignment="good/or evil"> and ending with </person>) and write it into another same xml file, named as approvenews.xml by editing or without editing the cotents( means editing newstitle, newsdescription ..etc)?

//************************************************** ************


Please help for this code ...
Thanx and Regards
rapraj

 
Old January 2nd, 2008, 01:14 AM
Authorized User
 
Join Date: Feb 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

We..l..well thanx to reply me......
My problem has been sort outed but one addition change is needed.
Actully, I have to read and display its contents of a xml file named as pendingnews.xml, given below


//************* pendingnews.xml *****************

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE lotr_characters [
<!ELEMENT person (name , email , newstitle , description)>
<!ATTLIST person alignment (good | evil) #REQUIRED>
<!ELEMENT name (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT newstitle (#PCDATA)>
<!ELEMENT description (#PCDATA)>
]>

        <ieee>
        <tgroup>
                <person alignment="good">
                <name>Raaj</name>
                <email>[email protected]</email>
                <newstitle>u can post news now</newstitle>
                <description>U can post news now..</description>
                </person>

                <person alignment="evil">
                <name>Deep</name>
                <email>[email protected]</email>
                <newstitle>Easy tool for u</newstitle>
                <description>There r ur desired tools available on net.</description>
                </person>

                <person alignment="good">
                <name>Pankaj: The Bhangra Guru</name>
                <email>[email protected]</email>
                <newstitle>Bhangra in IITK</newstitle>
                <description>There will bhagra dance in iitk on occasion of Antaragani</description>
                </person>

         </tgroup>
         </ieee>

//************************************************** ***********

I write this file by using php code shown below

//*************** lnewspost.php **********************

<?
 $post=$_POST['post'];
 $news_msg='';
 $xml='./doc/xml/pendingnews.xml';
 if($post)
   {
    if (version_compare(PHP_VERSION,'5','>='))
    require_once('domxml-php4-to-php5.php');
    //the folowing cotents are posted by GUI having field names
    //name,email..etc

    $name =$_POST['name'];
    $email =$_POST['email'];
    $newstitle =$_POST['newstitle'];
    $description =$_POST['description'];

    if(($email=='')|| ($newstitle=='')|| ($describe==''))
      {
       $tag=array(name, email, newstitle, description);
       $tagval=array($name, $email, $newstitle, $description);
       if(file_exists($xml))
         {
          if ($dom=domxml_open_file("$xml"))
             {
              $root=$dom->document_element();
              $bs=$root->get_elements_by_tagname('tgroup');
              if (count($bs)==1)
                 {
                  $totarr=count($tag);
                  $body=$bs[0];

for($r=0; $r<$totarr; $r++)
    {
    $body=$bs[0];
    $k=$dom->create_element($tag[$r]);
    $k->append_child($dom->create_text_node($tagval[$r]));
    $body->append_child($k);
    $body->append_child($dom->create_text_node("\n"));
    } //end of for $body->append_child($dom->create_text_node("\n"));
  } //end of 5th inner most "if"

  $dom->dump_file("$xml",false,false);
  $news_msg="Congratulations..! News has posted successfully";
  header("location: newspost.php?newsmsg=$news_msg");
  exit;
  } //end of 4th inner "if"
else
  {
   $news_msg="Sorry..! News file could not opend";
   header("location: newspost.php?newsmsg=$news_msg");
   }
 } //end of 3rd inner "if"
 else
   {
   $news_msg="File does not exists or write permission denied";
   header("location: newspost.php?newsmsg=$news_msg");
   }

} //end of 2nd inner "if"

}//end of 1st inner "if"
?>
//************************************************** ************


I had display the xml file (pendingnews.xml) by following code
//*********************** readnews.php *****************

<?
if( ! ($fp = fopen( "./doc/xml/pendingnews.xml" , "r" )) )
                die("Couldn't open xml file!");
                $person_counter = 0;
                $person_data = array();
                $xml_current_tag_state = '';

        function startElementHandler( $parser, $element_name, $element_attribs )
                {
                global $person_counter;
                global $person_data;
                global $xml_current_tag_state;
                if( $element_name == "PERSON" )
                        {
                        $person_data[$person_counter]["alignment"] = $element_attribs["ALIGNMENT"];
                        }
                else
                        {
                        $xml_current_tag_state = $element_name;
                        }
                }

        function endElementHandler( $parser, $element_name )
                {
                global $person_counter;
                global $person_data;
                global $xml_current_tag_state;
                $xml_current_tag_state = '';
                if( $element_name == "PERSON" )
                        {
                        $person_counter++;
                        }
                }

function characterDataHandler( $parser , $data )
                {
                global $person_counter;
                global $person_data;
                global $xml_current_tag_state;
                if( $xml_current_tag_state == '' )
                return;

                if( $xml_current_tag_state == "NAME" )
                        {
                        $person_data[$person_counter]["name"] = $data;
                        }

                if( $xml_current_tag_state == "EMAIL" )
                        {
                        $person_data[$person_counter]["email"] = $data;
                        }

                if( $xml_current_tag_state == "NEWSTITLE" )
                        {
                        $person_data[$person_counter]["newstitle"] = $data;
                        }

                if( $xml_current_tag_state == "DESCRIPTION" )
                        {
                        $person_data[$person_counter]["description"] = $data;
                        }
                }

 if( !($xml_parser = xml_parser_create()) )
                die("Couldn't create XML parser!");
                xml_set_element_handler($xml_parser, "startElementHandler", "endElementHandler");
                xml_set_character_data_handler($xml_parser, "characterDataHandler");
                while( $data = fread($fp, 4096) )
                        {
                        if( !xml_parse($xml_parser, $data, feof($fp)) )
                                {
                                break; // get out of while loop if we're done with the file
                                }
                        }

                xml_parser_free($xml_parser);
?>

        <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
        <html>
        <head>
        <title>Parsing the Sample XML File</title>
        </head>
        <body bgcolor="#ffffff">
        <?
                //echo$person_counter;
                for( $i=0 ; $i < $person_counter ; ++$i )
                //for( $i=0 ; $i < 5; ++$i )
                        {
                        $font_color = $person_data[$i]["alignment"] == "good" ? "#0000ff" : "#ff0000";
                        echo "" .
                        $person_data[$i]["name"] . "<br>\n";
                        echo "Email: &nbsp;&nbsp;" . $person_data[$i]["email"] . "<br>\n";
                        echo "News Title: &nbsp;&nbsp;" . $person_data[$i]["newstitle"] . "<br>\n";
                        echo "News Desc: &nbsp;&nbsp;" . $person_data[$i]["description"] . "<br>\n";
                        echo "<br>\n";
                        }
        ?>
        </body>
 if( !($xml_parser = xml_parser_create()) )
                die("Couldn't create XML parser!");
                xml_set_element_handler($xml_parser, "startElementHandler", "endElementHandler");
                xml_set_character_data_handler($xml_parser, "characterDataHandler");
                while( $data = fread($fp, 4096) )
                        {
                        if( !xml_parse($xml_parser, $data, feof($fp)) )
                                {
                                break; // get out of while loop if we're done with the file
                                }
                        }

                xml_parser_free($xml_parser);
?>

        <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
        <html>
        <head>
        <title>Parsing the Sample XML File</title>
        </head>
        <body bgcolor="#ffffff">
        <?
                //echo$person_counter;
                for( $i=0 ; $i < $person_counter ; ++$i )
                //for( $i=0 ; $i < 5; ++$i )
                        {
                        $font_color = $person_data[$i]["alignment"] == "good" ? "#0000ff" : "#ff0000";
                        echo "" .
                        $person_data[$i]["name"] . "<br>\n";
                        echo "Email: &nbsp;&nbsp;" . $person_data[$i]["email"] . "<br>\n";
                        echo "News Title: &nbsp;&nbsp;" . $person_data[$i]["newstitle"] . "<br>\n";
                        echo "News Desc: &nbsp;&nbsp;" . $person_data[$i]["description"] . "<br>\n";
                        echo "<br>\n";
                        }
        ?>
        </body>
        </html>



//************************************************** *******
My code in lnewspost.php is not writing the following 2 lines in xml file pendingnews.xml

 <person alignment="good"> //in the begning of block

 </person> //in the end of the block


My First question is how to write these line at right location ?(through php code in lnewspost.php) note that I wrote it manually


My second question is, How I can delete any perticular block / blocks (starting with <person alignment="good/or evil"> and ending with </person>) and write it into another same xml file, named as approvenews.xml by editing or without editing the cotents( means editing newstitle, newsdescription ..etc)?

//************************************************** ************


Please help for this code ...
Thanx and Regards
rapraj

 
Old January 8th, 2008, 06:55 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Why don't you use the DOM support to get the data out of the XML file as well? Its much simpler than the SAX way of doing things.

Also, I can't see anywhere in the lnewspost.php file where you create a person element (e.g. where is your create_element("person") line)?

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Authenticate login on same system hitu_patel_soft JSP Basics 0 April 20th, 2006 09:14 AM
Trying to Authenticate with Active Directory DrewPeterson89 C# 1 April 6th, 2005 10:39 AM
url authenticate salahuddin_iub Beginning PHP 2 September 20th, 2003 02:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.