Archive for December, 2007

750Part IVConnectionsListing 40-10(continued) $pollfile = poll.xml ; echo $_POST[ Raw_Poll_Option ][1]; (Adelphia web hosting)

Monday, December 17th, 2007

750Part IVConnectionsListing 40-10(continued) $pollfile = poll.xml ; echo $_POST[ Raw_Poll_Option ][1]; // Reading in the xml file as a string$fd = fopen($pollfile, r ) or die( Can t open file. ); $fstr = fread($fd, filesize($pollfile)) or die( Can t read file, checkpermissions. ); fclose($fd); // Format response sets. $PollName = str_replace( , , $_POST[ PollName ]); $PollName = str_replace( , _ , $_POST[ PollName ]); $RespSet = ; for ($r=0; $r<=5; $r++) { $currentRawPollOption = $_POST[ Raw_Poll_Option ][$r]; if (!empty($_POST[ Raw_Poll_Option ][$r])) { $Poll_Option[$r] = $_POST[PollName]- .str_replace( , , $currentRawPollOption); $Poll_Option[$r] = $_POST[PollName]- .str_replace( , _ , $currentRawPollOption); $currentPollOption = $Poll_Option[$r]; $RespSet .= t$currentRawPollOptionn ; } } //Add new poll data$separator = ; $divide = explode($separator, $fstr); $glue = t t$_POST[Poll_Startdate] t$_POST[Poll_Enddate] t$_POST[PollName] t$_POST[Poll_Question] t t
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Ftp web hosting - 749Chapter 40PHP and XMLUse this form to define

Saturday, December 15th, 2007

749Chapter 40PHP and XML

Use this form to define a poll:

Give this poll a short name, like ColorPoll.

This poll should begin on this date (MM/DD/YYYY):

This poll should end on this date (MM/DD/YYYY):

This is the poll question (e.g. Why did thechicken cross the road?):

These are the potential answer choices you want to offer (e.g. Yes, No, Say what?). Fill in only asmany as you need. Keep in mind that brevity is the soul of good poll- making.






Listing 40-10:A script to write out an XML file (writepoll.php) In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Kids web site - 748Part IVConnectionsListing 40-8(continued) foreach ($ingredients as $ingredient) {

Saturday, December 15th, 2007

748Part IVConnectionsListing 40-8(continued) foreach ($ingredients as $ingredient) { print

Ingredient: $ingredient ; } print

Directions: $directions ; print

Serves $servings ; ?> SimpleXML functionsTable 40-7 lists the most important SimpleXML functions, with descriptions of what they do. Table 40-7: SimpleXML Function Summarysimplexml_load_file(file)Import and parse a file. simplexml_load_string(string)Import and parse a string. simplexml_import_dom(DomDocument)This function allows you to convert a DomDocumentobject into a SimpleXML object, and then treatedjust like an imported XML file or string. A Sample XML ApplicationThis series of scripts will write out XML to a file by using data from an HTML form, and thenwill allow you to edit the values in that file. Listing 40-9 is an HTML form that can be used by nontechnical users to define forms. (Theydon t care that this data will be formatted and stored in XML.) Listing 40-10 is a script to writeout the XML file. Listing 40-9: A form to collect values for an XML file (pollform.php) Make-a-poll

Make-a-poll


If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Web hosting script - 747Chapter 40PHP and XMLFunctionBehaviorxml_set_character_data_handlerSets the handler function to

Friday, December 14th, 2007

747Chapter 40PHP and XMLFunctionBehaviorxml_set_character_data_handlerSets the handler function to call whenever character (parser, cd_handler)data is encountered. The handler function takes a stringcontaining the character data as an argument. xml_set_default_handlerSets the default handler. If no handler is specified for an (parser, handler)event, the default handler is called if it is specified. Takes as arguments the parser and a string containingunhandled data, such as a notation declaration or anexternal entity reference. SimpleXML APIThe SimpleXML API is new in PHP5. Characterized as an object-mapping API, SimpleXML dis- penses with Web standards and absolute flexibility in favor of simplicity and modest memoryusage. If you just need to read some data from an XML document and write some other databack in, the SimpleXML likely will require the fewest lines of code of all possible approachesto the problem. Here s the idea behind SimpleXML: As in the DOM approach, SimpleXML parses an XML docu- ment and holds the whole thing in memory. However, rather than hold the document as aDOM object (which you must further manipulate before you can use its contents), its ele- ments are stored as native PHP variables and so are immediately useable. Because manyDOM tasks do not actually require you to traverse all the children and parents of a document, but rather perform repetitive tasks on well-defined nodes, SimpleXML ultimately constitutes aPHP-specific compromise between the SAX and DOM approaches. Using SimpleXMLWhen using SimpleXML, you read a passage of XML text either a string or a file into avariable with the function simplexml_load_string()or simplexml_load_file(). Youthen have a local object you can refer to directly. Listing 40-8 shows how the SimpleXML APIcan be used to get variable values out of an XML file with just a few lines of code. Listing 40-8 demonstrates a typical use of SimpleXML. Listing 40-8:SimpleXML sample (simplexml.php) ingredients; $directions = $recipe->directions; $servings = $recipe->servings; Continued45
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Affordable web design - 746Part IVConnectionsIn the following example, we create an

Thursday, December 13th, 2007

746Part IVConnectionsIn the following example, we create an XML parser that reads in data as ASCII, turns off casefolding, and spits out the output as UTF-8. $new_parser = xml_parser_create( US-ASCII ); $case_folding = xml_parser_get_option(XML_OPTION_CASE_FOLDING); echo $case_folding; $change_folding = xml_parser_set_option($new_parser, XML_OPTION_CASE_FOLDING,0); $target_encoding = xml_parser_get_option(XML_TARGET_ENCODING); echo $target_encoding; $change_encoding = xml_parser_set_option($new_parser, XML_OPTION_TARGET_ENCODING, UTF-8 ); SAX functionsTable 40-6 lists the most important SAX functions, with descriptions of what they do. Table 40-6: XML SAX Function SummaryFunctionBehaviorxml_parser_create([encoding])This function creates a new XML parser instance. Youmay have several distinct parsers at any time. The returnvalue is an XML parser or false on failure. Takes one optional argument, a character-encodingidentifier (such as UTF-8). If no encoding is supplied, ISO-8859-1 is assumed. xml_parser_free(parser)Frees the memory associated with a parser created byxml_parser_create(). xml_parse(parser, data[,final])This function starts the XML parser. Its arguments are aparser created by using xml_parser_create(), astring containing XML, and an optional finality flag. Thefinality flag indicates that this is the last piece of datahandled by this parser. xml_get_error_code(parser)If the parser has encountered a problem, its parse fails. Call this function to find out the error code. xml_error_string(errorcode)Given an error code returned byxml_get_error_code(), it returns a string containinga description of the error suitable for logging. xml_set_element_handler(parser, This function actually sets two handlers, which are start_element_handler,simply functions. The first is a start-of-element handler, end_element_handler)which has access to the name of the element and anassociative array of its elements. The second is an end- of-element handler, at which time the element is fullyparsed.
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

745Chapter 40PHP and XMLSAX optionsThe XML parser in (Personal web server)

Thursday, December 13th, 2007

745Chapter 40PHP and XMLSAX optionsThe XML parser in the SAX API has two configurable options: one for case folding and theother for target encoding. Case foldingis the residue of a series of past decisions and may not be relevant now that XMLhas been definitely declared case sensitive. Early versions of SGML and HTML were not casesensitive and, therefore, employed case folding (making all characters uppercase or lower- case during parsing) as a means of getting a uniform result to compare. This is how yourbrowser knew to match up a

tag with a

tag. Case folding fell out of favor due toproblems with internationalization, so after much debate XML was declared case sensitive. When case folding is enabled, node names passed to event handlers are turned into all upper- case characters. A node named mynodewould be received as MYNODE. When case folding isdisabled, a
tag will not match a closing tag. Case folding is enabled by default, which violates the XML 1.0 specification. Unless you disableit by using xml_parser_set_option()as explained in a moment, your event handlersreceive tags in uppercase letters. Event handlers receive text data from the XML parser in one of three encodings: ISO-8859-1, US-ASCII, or UTF-8. The default is ISO-8859-1. The encoding of text passed to event handlersisknown as the target encoding.This is by default the same encoding as in the source docu- ment, which is known as the source encoding.You can change the target encoding if you needto process the text in an encoding other than the encoding it was stored in. Encoding options are retrieved and set with the functions xml_parser_get_option() and xml_parser_set_option(). Case folding is controlled by using the constantXML_OPTION_CASE_FOLDING, and target encoding by using the constant XML_OPTION_ TARGET_ENCODING. NotePHP and InternationalizationComputer programs store letters as integers, which they convert back to letters according toencodings. Early programs used English, which conveniently needs only one byte (actually onlyseven bits) to represent all the common letters and symbols. This encoding standard was pro- mulgated in 1968 as ASCII (American Standard Code for Information Interchange). However, programmers soon found that English has an unusually small number of characters, and thus the only languages that can be expressed with any completeness in ASCII are Hawaiian, Kiswahili, Latin, and American English. Ever since then, programmers concerned with interna- tionalization have tried to promote encoding standards that promise to assign a unique integerto every one of the letters of every one of the world s alphabetical languages. The result of thiseffort is referred to as Unicode. The three encodings supported by PHP s XML extension are ISO-8859-1, US-ASCII, and UTF-8. US-ASCII is the simplest of these, a slight renaming of the original 7-bit ASCII set. ISO-8859-1isalso known as the Latin1, Western, or Western European encoding. It can represent almost allwestern European languages adequately. UTF-8allows the use of up to 4 bytes to represent asmany of the world s languages as possible. If your XML document is written in Han-gul or Zulu, you have no choice but to use UTF-8.45
We recommend high quality webhost to host and run your jsp application: christian web host services.

744Part IVConnectionsThe simple example in Listing 40-7 shows (Http web server)

Wednesday, December 12th, 2007

744Part IVConnectionsThe simple example in Listing 40-7 shows all the basic XML functions in use. Listing 40-7:A simple XML parser (simpleparser.php) $name => ; } // Call this at the end of every elementfunction endElement($parser, $name) { print n ; } // Call this whenever there is character datafunction characterData($parser, $value) { print $value
; } // Define the parser$simpleparser = xml_parser_create(); xml_set_element_handler($simpleparser, startElement , endElement ); xml_set_character_data_handler($simpleparser, characterData ); // Open the XML file for readingif (!($fp = fopen($file, r ))) { die( could not open XML input ); } // Parse itwhile ($data = fread($fp, filesize($file))) { if (!xml_parse($simpleparser, $data, feof($fp))) { die(xml_error_string(xml_get_error_code($simpleparser))); } } // Free memoryxml_parser_free($simpleparser); ?>
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

743Chapter 40PHP and XMLSAXThe (Web hosting directory) Simple API for XML

Tuesday, December 11th, 2007

743Chapter 40PHP and XMLSAXThe Simple API for XML is widely used to parse XML documents. It is an event-based API, which means that the parser calls designated functions after it recognizes a certain trigger inthe event stream. SAX has an interesting history, especially in contrast to the DOM. The SAX API is not shep- herded by an official standardizing body. Instead, it was hammered out by a group of pro- grammers on the XML-DEV mailing list, many of whom had already implemented their ownXML parsers (in Java first!) without a standard API. You can learn more at the Web sites ofSAX team members, such as www.saxproject.org. SAX works from a number of event hookssupplied by you via PHP. As the parser goes throughan XML document, it recognizes pieces of XML such as elements, character data, and externalentities. Each of these is an event. If you have supplied the parser with a function to call forthe particular kind of event, it pauses to call your function after it reaches that event. Theparsed data associated with an event is made available to the called function. After the event- handling function finishes, the SAX parser continues through the document, calling functionson events, until it reaches the end. This process is unidirectional from beginning to end of thedocument the parser cannot back up or loop. A very simple example is an event hook that directs PHP to recognize the XML element
and substitute the HTML tags

around the characterdata. If you wrote this event hook, you could not specify a particular paragraph instead, the function is called for every instance of this event. The parser behind the scenes in the PHP SAX extension is libxml2, which you can readabout on its project site at www.xmlsoft.org. Prior to version 5, PHP used James Clark s expat, a widely used XML parser toolkit. Moreinformation about expatcan be found on Clark s Web site at www.jclark.com/xml/. If youcompile with libxml2, you should be able to use all your PHP4 SAX code in PHP5 withoutproblems. Unfortunately, the term parsercan refer either to a software library such as libxml2, or to ablock of XML-handling functions in PHP. Verbs such as createand callindicate the latter, more specific meaning. Any PHP XML function that uses the term parseralso refers to thelatter meaning. Using SAXHow you use the SAX will depend on your goals, but these steps are common: 1.Determine what kinds of events you want to handle. 2.Write handler functions for each event. You almost certainly want to write a characterdata handler, plus start element and end element handlers. 3.Create a parser by using xml_parser_create()and then call it by usingxml_parse(). 4.Free the memory used up by the parser by using xml_parser_free(). Caution45
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

742Part IVConnectionsTable (Adelphia web hosting) 40-3 lists the most important methods

Tuesday, December 11th, 2007

742Part IVConnectionsTable 40-3 lists the most important methods of the DomDocumentclass. Table 40-3: DomDocument Class SummaryMethodBehaviorcreateElement(name)Creates a new element whose tag is the passed string. Youmust append this element to another element usingDomNode->appendChild(). createTextNode(character_data)Creates a new text node (DomTextobject). You mustappend this node to another node using DomNode- >appendChild(). save(filename)Dumps XML from memory to a designated file. saveXML([node])Dumps XML from memory to a string. Optional parameter isa DomNode object. Table 40-4 lists the most important methods of the DomNodeclass. Table 40-4: DomNode Class SummaryMethodBehaviorappendChild(newnode)Attaches a node to another node. removeChild(child)Removes the child node. Table 40-5 lists the most important methods of the DomAttrclass. Table 40-5: DomAttr Class SummaryMethodBehaviorname()Returns an attribute name. value()Returns the value of an attribute.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

741Chapter 40PHP and XML$body = $root->appendChild($body); $body->setAttribute( bgcolor , #87CEEB ); (Free web hosting music)

Monday, December 10th, 2007

741Chapter 40PHP and XML$body = $root->appendChild($body); $body->setAttribute( bgcolor , #87CEEB ); $graff = $doc->createElement( P ); $graff = $body->appendChild($graff); $text = $doc->createTextNode( This is some text. ); $text = $graff->appendChild($text); $doc->save( test_dom.xml ); ?> DOM functionsTable 40-1 lists the most common DOM functions. You must call one of these functions beforeyou can use any of the other DOM XML functions! Table 40-1: DOM XML Top-Level Function SummaryFunctionBehaviordomxml_open_mem(string)Takes a string containing an XML document as an argument. This function parses the document and creates a Documentobject. domxml_open_file(filename)Takes a string containing an XML file as an argument. Thisfunction parses the file and creates a Document object. domxml_xmltree(string)Takes a string containing an XML document as an argument. Creates a tree of PHP objects and returns a DOM object. Note:The object tree returned by this function is read-only. domxml_new_doc(version)Creates a new, empty XML document in memory. Returns aDocument object. Table 40-2 lists the most important classes of the DOM API. Table 40-2: XML DOM Class SummaryClassBehaviorDomDocumentThis class encapsulates an XML document. It contains theroot element and a DTD if any. DomNodeEncapsulates a node, aka an element. A node can be theroot element or any element within it. Nodes can containother nodes, character data, and attributes. DomAttrThis class encapsulates a node attribute. An attributeis auser-defined quality of the node.
You want to have a cheap webhost for your apache application, then check apache web hosting services.