Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




DomDocument: Setting Attributes To A New Node


I'm trying to create a single function to append new nodes to a
DOMDocument object:

public function addElement( $element, $name, $value = '', $attrs = Null
)
{
if( !( $created = $this->createElement( $name, $value ) ) )
throw new Exception( 'Could not create a new node ' );

if( !( $child = $element->appendChild( $child ) ) )
throw new Exception( 'Could not append a new node ' );

// Process and attachs the new attributes from array $attrs if
any...
// if( $attrs )
// foreach( $attrs as $attribute => $value )
// ...
}

So far, so good. Now I want to set attributes and its values of the
recent created node (playing with createAttribute() and setAttribute(),
but I can't get the DOMElement from the new child DOMNode. Is it
possible without issuing getElementsByTagName() or getElementById() ??

Is another easy way -using DomDocument object- to create a new
element (such <table width="50%" border="0">...</table>) which has its
attributes and its values ?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
PHP SOAP And Setting Attributes
Does anyone know if you can set attributes using PHP's built-in SOAP
library?

I know you can do it with PEAR::SOAP but cannot see a way to do it with
the built-in one.

XML - Node Manipulation
I was wondering if anyone could point me to any references regarding manipulating XML Child Nodes. I am currently retrieving data from XML in a manner that is useful. However, I am scratching my head when I need to change that information.

Select Node From DOM By ID?
I'm looking for a way to select a <div> by id from an entire xhtml page. I'm not a very experienced coder, but I'm learning... Does php have a fuction for this? it would be like

$entire_page = "entire xhtml page fetched from DB which contains <div id='wanted_div'>some content I want</div>";

$my_wanted_div =   .... // how do I get the content of 'iwantthisdiv' here?

Children Of Child Node??
Is there any function or way to access the children of a child node using DOM???

I mean if i have the xml structure as:
<app>
<app_data>
<data name='method'><value>sum_dif</value></data>
<data name='val1'><value>123</value></data>
<data name='val2'><value>456</value></data>
<app_data> // child of child node
<data name='coool'><value>divo9</value></data>
<data name='sands'><value>007</value></data>
<data name='make'><value>bond</value></data>
</app_data>
</app_data>
</app>
How can I access the data in the child node <app_data>?

Writing A Node To An XML File
I want to write a node or nodes to an existing xml document. I don't need to create a new document, thanks but no thanks.

Judging from various posted topics I've seen. It appears the php DOM for XML isn't quite there yet and has a lot of bugs. Not only that it takes a few months before web hosters update versions of php.

I tried the pear classes, but they're so poorly documented, there's no example, there's nobody you can contact at Pear for hlep. If you ask for help on forums, you get no reply's so obviously not many ppl are using these classes.

I wonder..... if there's a push from say mySQL to stall or slow down PHP's functionality for XML?

Any ideas on how to write a node or nodes into an existing XML file..... without a bunch a array manipulation?

Deleting A Node With Known Position In DOM (XML)
I have a a xml with a very basic structure:

<root>
  <template name="name0">data0</template>
  <template name="name1">data1</template>
  <template name="name2">data2</template>
  <template name="name3">data3</template>
  <template name="name4">data4</template>
  <template name="name5">data5</template>
  <template name="name6">data6</template>
</root>

I'm trying to remove the 4th node in the file (named name3). The code i'm using for this is:

<?
    $i = 3; //Hoping to delete the 4th node.
    $doc = new DOMDocument(); $doc->load('file:///var/templates.xml');
 
    $items = $doc->getElementsByTagName('template'); $items2 = $items->item($i);
    $itemg = $items2->nodeValue; echo $itemg; //It does return the value of the item i'm trying to delete.
 
    $itemg = $items->removeChild($items2); //Return: "Fatal error: Call to undefined method DOMNodeList::removeChild()"
?>

As said above, the script return Fatal error: Call to undefined method DOMNodeList::removeChild(). I've no idea why it isn't working, and definitely not an idea what the correct code would be.

Can $node->node_value() Return A Null Value?
I am using the following function to access a nodes value from an XML
file. It works fine until it discovers a empty tag. I would like to
have the option of leaving some tags empty for my script.

..
..
..
function foutput_contact ($node_name) {
$xml_document = domxml_open_file('xml/contacts.xml');
if ($xml_document) {
$nodes= $xml_document->get_elements_by_tagname($node_name);
$nodeCount = count($nodes);
$node = $nodes[0];
if ($node) {
$node = $node->first_child();
return $node->node_value();
}
}
}

The error is returned at the line 'return $node->node_value()' but
only when I use an empty node. Can this script be modified to allow
empty nodes?

Php And Xml DomDocument
a error occurs in my class Articles in which i try to add an element
to an existing xml-file.
$var_dump($channels) >>>object(DOMNOdeList)+6 (0) {}
$var_dump($channels->length) >>>int(0)
$var_dump($channels->item(0)) >>>NULL

The tag article exists in the xml-file but it were not found by method
getElementsByTagName.
Following error were occur:

Fatal error: Call to a member function appendChild() on a non-object
in ...

class Article extends DomDocument
{
public function __contruct()
{
parent::__contruct(&#391;.0','utf-8');
}
public function addArticle($title, $text)
{
$newItem = $this->createElement('item');
$newTitle = $this->createElement('title');
$newTitle->appendChild($this->createTextNode($title));
$newItem->appendChild($newTitle);
$newText = $this->createCDATASection($text);
$newItem->appendChilde($newText);
$channels = $this->getElementsByTagName('articles');
//hier bekomme ich den Fehler, obwohl es den Tag "arcticles" gibt
$channels->item(0)->appendChild($newItem);
//andere Ideen wie ich einen neuen Text in einer bestehender xml-

PHP 5 DomDocument
Im using the DomDocument class in PHP5 to parse thru a xml file, but it
keeps timing out on the load method :

$dom = new DomDocument();
$dom->load("<some url>");

Browsing to the url in a browser does load, although it takes about 11
minutes, its a big amount of data.

The lines above run for 2 minutes then the script stops :

Warning: DOMDocument::load(http://...) [function.DOMDocument-load]:
failed to open stream: HTTP request failed!

Does anyone know if there is a setting meaning it can only run for 2
minutes that i can increase, i presume its not the normal php page
timeout setting, because the error message would say that.

After I Load An XML File, Can I Sort It By Node Attribute
After loading an xml file, is it possible to sort it by attribute?

For example, I have the following xml file:

<xml...
<diary>
<entry date="2005-01-01">I went to the park</entry>
<entry date="2005-01-03">Sold the car today</entry>
<entry date="2005-01-02">Went for a stroll</entry>
</diary>

When I go to load this using PHP, I would use some this similar to
this:

$xmldoc = domxml_open_file('diary.xml', DOMXML_LOAD_DONT_KEEP_BLANKS);

$node = $xmldoc->document_element();

Before I go storming through the xml tree outputing along the way, can
I sort it by (in this case) date?

[DOM XML] How To Encode A Node Content (Accentuated Characters)
I'm trying to generate a RSS newsfeed using the DOM XML functions. However I
can't find a way to use accentuated characters. I even tried to specify a
character encoding set but it doesn't solve the problem.

Error I get :
XML Parsing Error: not well-formed
Location: news.php?action=syndicate&format=rss2
Line Number 1, Column 102:<?xml version="1.0" encoding="ISO-8859-15"?><rss
version="2.0"><channel><title>Website title - News (
----------------------------------------------------------------------------
-----------------------------------------------------------^

The not well-formed character is an accentuated character, as you can see on
the following code sample :

<?php

header ('content-type: text/xml');

echo ('<?xml version="1.0" encoding="ISO-8859-15"?>');

$dom_doc = domxml_new_doc (&#391;.0');

$rss_el = $dom_doc->create_element ('rss');
$rss_el->set_attribute ('version', &#392;.0');
$rss_el = $dom_doc->append_child ($rss_el);

$channel_el = $dom_doc->create_element ('channel');
$channel_el = $rss_el->append_child ($channel_el);

$title_el = $dom_doc->create_element ('title');
$title_el = $channel_el->append_child ($title_el);
$title_el->set_content ('Website title - News (ŕéčů)');

echo ($dom_doc->html_dump_mem ());

?>

Removing the accentuated characters from the title generates a well formed
XML file. Note that I also tried to encode the characters using the
htmlentities function but it didn't change anything.

Virtual Xml DOMDocument
I would like to create a class that acts like an Xml document so that I
can pass it through an XSLT transform. But, there is never any
Document created.

Basically, what I'm trying to do, is a virtual XML layer over a
persistence framework that allows you to access a database with XPath
queries. I've already done something like this in another project and
language, but, it's too custom to pass into an XSLT transform.
Also, the database huge. I only want to read the portions in...
requested by all the XPATH stuff in the XSLT file.

So, I basically want to do something like.....

class DBDOMDoc extends DOMDocument {
var $PersistenceObject; // This object is the head of the
hierarchy...

.... override reading of the nodes, with Persistence Framework
requests (db queries )
}

$xml = new DBDOMDoc;
$xml->PersistenceObject = $someDBObj;

// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules

if ( $argc == 4 && $argv[3]=='dom' ){

echo $proc->transformToDoc($xml)->firstChild->wholeText;
} else {
echo $proc->transformToXml($xml);
}



Using DOMDocument To Parse XML.
I'm sending xome XML to a server who then sends XML back to me.  I use fread and get the XML sent back and I can echo my $xml variable and it has the xml.  I can then make a DOMDocument but when I use loadXML it stops and doesn't do anything after that line, including displaying the HTML I have below all my php code.  Is there something I need to configure with php for loadXML to work?  If so, how do I go about doing that?  Code:

Debugging DomDocument Objects
What is the best way to view the contents of a DomDocument Object? print_r() and var_dump() just give me empty objects. Here is my code, if you're curious:

$dom = new DOMDocument();
$dom->loadHTML("<html><body><p>Hello World</p></body></html>");
print_r($dom);

Warning: Domdocument() Expects At Least 1 Parameter
I have this script

-----------------------------------------------------------
<?php
$doc = new DOMDocument();
$doc->load('books.xml');
echo $doc->saveXML();
?>
-----------------------------------------------------------

But when I run it I get this ugly message...

-----------------------------------------------------------
Warning: domdocument() expects at least 1 parameter, 0 given in
C:ProgrammiApache GroupApache2htdocsappaimlook.php on line 2
Fatal error: Call to undefined function: load() in C:ProgrammiApache
GroupApache2htdocsappaimlook.php on line 3
-----------------------------------------------------------

My php version is 4.3.8 (with Apache 2.0 on windows 2000).

PHP5 DOMDocument: Specifying Encoding Programmatically
How do I tell DOMDocument->load() what encoding I want it to use?

Longer: I search for and process XML files from elsewhere, and need to
transform them with some XSLTs. No problem. Using PHP5 and the DOM
library, everything's a snap. Worked fine, up till now. Today, funky
characters were in the XML file -- "smart" quotes from Word, it looks
like. Anyways, DOMDocument->load complained about them, saying that
they weren't UTF-8, and to specify the encoding.

Lo and behold, the encoding is not specified in these XML files. If I
add in 'encoding="iso-8859-1"' to the header, it works fine. The rub is
I have no control over these XML files.

Reading the file into a string, modifying its header and writing it back
out to another location seems to be my only option, but I'd prefer to do
it without having to use temporary copies of the XML files at all. Is
there any way to simply tell the parser to parse them as if they were
iso-8859-1?

PHP5:DomDocument:nice Looking XMLS
I am creating som XML files with PHP5 built-in DomDocument Class. Everything works fine, but saveXML() returns the whole XML in one line. Is there any possibility to get good-looking, human readable, indented XML files with line breaks?

PHP Version 4.3.10 - Warning: Domdocument() Expects At Least 1 Parameter, 0 Given
I'm getting the following error(s) below and I'm at a bit of a loss as
to how to correct it. When I give it a parameter it then complains it
needs two parameters and the second one being an integer or something
like that.

Warning: domdocument() expects at least 1 parameter, 0 given in
orders.php on line 157

Warning: domdocument() expects at least 1 parameter, 0 given in
orders.php on line 158

Fatal error: Call to undefined function: loadxml() in orders.php on
line 159

The lines in question are:
$xml = new DOMDocument;
$xsl = new DOMDocument;
$xml->loadXML($row['fetch_orders']);
$xsl->load('fetch_orders.xsl');
$proc = new xsltprocessor;

phpinfo shows the following:
Loaded Modules: mod_php4, mod_setenvif, mod_so, mod_unique_id,
mod_log_forensic, mod_usertrack, mod_headers, mod_expires,
mod_cern_meta, mod_proxy, mod_digest, mod_auth_db, mod_auth_anon,
mod_auth, mod_access, mod_rewrite, mod_alias, mod_userdir, mod_speling,
mod_actions, mod_imap, mod_asis, mod_cgi, mod_dir, mod_autoindex,
mod_include, mod_info, mod_status, mod_negotiation, mod_mime,
mod_mime_magic, mod_log_config, mod_define, mod_env, mod_vhost_alias,
mod_mmap_static, http_core

domxml
DOM/XML enabled
DOM/XML API Version 20020815
libxml Version 20616
HTML Support enabled
XPath Support enabled
XPointer Support enabled
DOM/XSLT enabled
libxslt Version 1.1.12
libxslt compiled against libxml Version 2.6.16
DOM/EXSLT enabled
libexslt Version 1.1.12

xml
XML Support active
XML Namespace Support active
EXPAT Version expat_1.95.8

xslt
XSLT support enabled
Backend Sablotron
Sablotron Version 1.0.1
Sablotron Information Cflags: -O -pipe Libs: -L/usr/local/lib -liconv
-lexpat Prefix: /usr/local

PHP4 Equivalent Of PHP5 DOMDocument->loadHTML()?
I have an HTML string that I receive from a variable.  It's not well-formed but contains some elements, I need to manipulate.  Basically, just adding and removing some elements.  After reading about PHP5's beautiful DOMDocument->loadHTML(), I realized it could be done.  However, our server is using php4 =(.  Is there a PHP Class floating around that may do the trick?

I almost do not want the solution to use PHP4's DOM functionalities bc I read that they don't translate well when you update PHP to version 5. 

Setting Cookies, Setting Timestamp Instead...
im setting cookies for my login and instead of storing the values i want it to, its storing a timestamp instead my code is in a few pages, althoug ill summerise my data, and only post the code that creates the cookies: Code:

LDAP Attributes
I've got a problem with Sun's iPlanet Directory Server 5.1. I'm writing applications in PHP, and so far it's all going well. However, there appear to be some attributes that I can't fetch - one of these is passwordexpirationtime. I can get the usual stuff like uid, cn etc. but this (and some other attributes) cannot be fetched.

I've tried binding anonymously, and as the directory administrator - but I still get the same result. It appears that I am limited to the following :-

uid
givenname
objectclass
sn
cn
userpassword
creatorsname
modifiersname
createtimestamp
modifytimestamp
mail
telephonenumber
employeetype
dn

Is there anything that anyone could suggest ? Any help would be much appreciated - I need to provide a facility to let my users know when their password is about to expire.

NuSOAP + Attributes?
I've never used SOAP before, so am more than a little foggy on it. Just
doing a project where it's basically the only way, and due to
limitations on the server, I have to use nuSOAP (unless there's a
better option that runs as a class...). Anyway, I've got it talking to
the server happily.. Just not passing attributes. This is what I need,
in straight SOAP XML stuff...

<platformCore:email>eblack@yahoo.com</platformCore:email>
<platformCore:password>Cracker1</platformCore:password>
<platformCore:account>111111</platformCore:account>
<platformCore:role internalId="3"/>

And as far as I can see nuSOAP is called by

$foo->call('login',$array);

or similar. This is working. The bit I'm having trouble with is setting
the internalId attribute on the role.

array(
'email'=>'eblack@yahoo.com',
'password'=>'Cracker1',
'account'=> ?',
'role'=> array('name'=>'role', 'value'=>'') //need to add the
internalId attribute
//'role internalID="14"' => '' // outputs XML like
);

Something like that. I've tried so many things, and get various errors
back.. basically no dice though. It's talking, but rejecting me if I
don't have an internalID or something else isnt right in the SOAP XML.

For reference the second option above (commented out one) outputs
something like this in XML (I assume...)

<platformCore:role internalId="14"></platformCore:role internalId="14">

And it falls over at the whitespace in the closing tag. The first
option just achieves nothing....

Add Attributes Elements To An XML Tag?
Whats the PHP code to add an XML tag with an attribute element in my
SOAP message body. With output formatted corresponding to the following
example:

<PRSADRVBL soortEntiteit="R">
............<other xml>...........
</PRSADRVBL>

Parsing XML Attributes
I am using the following code and want to retrieve an attributes value.
I want to loop through the xml file and add the attribute values to an
array. The line in question is marked with "<---?" below.

I have included both the PHP and XML.

################################################## #############
<?php
$headlines = array();
$urls = array();
$match = "";

function opening_element($parser, $element, $attributes) {
global $match;

if ($element == "HeadLine"){
$match = "headline";
}
elseif ($element == "NewsItemRef"){
$match = "url";
}
}.........

Read Xml Attributes
i am trying to read the xml tag attributes in php but quite not getting it. If anyone have previously done it could you please help me out. I am including the xml code with the post. Code:

My Sql Length Attributes.
why does the length attribute, to set the character length of what is added to a a mysql field, only seem to work on varchar and not text?

Combining Like Attributes
I've got a master inventory list that includes the Item Description, it's location, and quantity. If I have duck tape in 3 places it will show:

Duck Tape - Office - 2
Duck Tape - Shop - 27
Duck Tape - Trailer - 1

Can I combine all the duck tapes (and there are other multiples in this list that would need to be combined as well) it so the master list says:

Duck Tape - 30
Etc...

Using Class Attributes?
I just picked up PHP& MySQL Web Development by Luke Welling and Laura Thomson 3rd edition and am having problems with the examples they use under 'Using Class Attributes'. Specifically, they say that "If an attribute of your current class is called $attribute, you refer to it as $this->attribute ..." What I don't understand is, in some of the examples the attribute has the $ and some it doesn't. I'm assuming that there is a reason for this, and that it's not merely a typo.

Quotes Around HTML Attributes
If I am using echo to return some HTML how do I get quotes around the attributes? In ASP I would use a double quote i.e.

response.write ("<h1 align=""center"")

to give

<h1 align="center">

but this doesn't work in PHP, I'm hoping someone can enlighten me!

Product Attributes Problem?
While trying to design a database for shopping cart i encountered few problems which i am mentioning here.

I had hierarchical level of categories for products for which i designed table as:

Simplexml + Namespace +attributes
I have an XML file with some elements like those below

<core:District Id="AB01">
<core:Name>NORTH EAST</core:Name>
<core:Association Type="type1">VALUE 1a</core:Association>
<core:Association Type="type2">VALUE 1b</core:Association>
<core:Association Type="type3">VALUE 1c</core:Association>
</core:District>
<core:District Id="AB02">
<core:Name>NORTH WEST</core:Name>
<core:Association Type="type1">VALUE 2a</core:Association>
<core:Association Type="type2">VALUE 2b</core:Association>
<core:Association Type="type3">VALUE 2c</core:Association>
</core:District>

I'm trying to parse it using simplexml

I have:

$districts = $xmlfile->children($core);

foreach ($districts as $key => $value)
{
echo "Name = " . $value->Name . "
";
echo "Region1 = " . $value->Association[0] . "
";
echo "Region2 = " . $value->Association[1] . "
";
echo "Region3 = " . $value->Association[2] . "
";

}

This works fine, but I am unable to access the Id attribute in the
opening District element, i.e. AB01 or AB02.

Would anyone be able to suggest how I might get that value with
simplexml?

Objects As Object Attributes
I'm building a site where i'm trying to use the DOMApi supplied with PHP. The basic idea is to make all my bricks as small xml-nodes that can be apprehended by others.

The problem is that i'm having problems with defining objects as attributes. I'm a bit rusty with the PHP-syntax so please bear over with me.

class Treatmentlist extends DOMNode
{
   
   private $pDomL;
   private $pParent;
   
   private $pInitialized;

   public function __construct($aParent)
   {
      $pParent = $aParent;
      $pDom = $aParent->ownerDocument;
   }

.... some other methods ...

}

The problem is that when I refer to $pDom, it doesn't recognize it as an object of the type DOMDocument. What would solve my problem ?

Soapserver Reading Xml Attributes
I have a issue with the php5 soap extention, i did setup an soap server and it is recieving data but in the xml the other party used attributes. below a code snippet from the recieved call. I am talking about the "datumtijd" is datetime in dutch Code:

Can You ECHO Object Attributes?
I receive the error "Catchable fatal error: Object of class Car could not be converted to string" whenever I try to echo one of its attributes.  For example:

$car = new car();
echo $car->model;

model is a public attribute so is this error normal?  I'm trying to avoid writing a display function or passing the attribute's value to a local variable.

Editting XML Attributes With SimpleXML?
Ive been trying to figure out how to edit XML Node Attributes, Can someone point me in the right direction? ....

Removing Attributes From Html Tags
I want to build a class which will return a stripped version of variable containing HTML tags.

In my constructor i will use strip_tags to get rid of the unwanted tags in the variable.

After that i'll call a method cleanup() which has to do the hard work.

Lets say i fill an array with values containing attributes like Onclick Onmouseover Style in my constuctor.

I will allow de <a> tag to be used, but i want to strip the tag from attributes mentioned above.

Need Access To Default File Attributes
When I was first learning php, I created an upload script. The basics of the script had:

<form method="POST" ENCTYPE="multipart/form-data">
<input type="file" name="FILE">
<input type="submit" name="SUBMIT" value="Upload">
</form>

Then in the submit section, it accesses the filename and filesize by virtue of a default php ability to extract these attributes by using: $FILE_name and $FILE_size (where _name gives the name of $FILE and _size gives the size of $FILE).

if($SUBMIT)
echo " Filename: $FILE_name <br> Filesize: $FILE_size";

Also, I did add the necessary lines to handle the post variables, like so:

$FILE = $_POST['FILE'];
$SUBMIT = $_POST['SUBMIT'];

I have tried to mimic this script in a new upload script, but am unable to access those same attributes (_name and _size).

At the time of my original upload script, we were running it on a Linux server (but I don't remember what we were running for a php version). Currently, I am running PHP 4.2.3 on Mac OS 10.2.8 server.

One thought I had was that maybe PHP 4.2.3 no longer supports _name and _size. Or, maybe I am not handling the retrieval of the POST var for the file correctly? I wonder this because I did try print_r($_POST) and I only got the submit returned as a post var.

Strip Html Tags ATTRIBUTES With Reg Exp
I want to strip html attribute within a tag. e.g.:

<td class="blah" colspan="2" bgcolor="#ffffff">blah</td>

And I want to leave the 'colspan="2"' intact. result after stripping with reg exp:

<td colspan="2">blah</td>

Regex: Want To Eliminate The Excess Attributes
In netscape bookmark files, there are lots of lines like this:
<DT><A HREF="http://www.commondreams.org/" ADD_DATE="1091500674"
LAST_CHARSET="ISO-8859-1" ID="rdf:#$uiYyb3">Common Dreams</A>

I want to eliminate the excess attributes and values to get this:
<DT><A HREF="http://www.commondreams.org/">Common Dreams</A>

I almost succeed with this:
$lines[]=preg_replace("{(<A HREF=".*")( ADD.*)(>.*</A>)}","13",
$line);

The only problem is the explicit "ADD". The code only works is there is
an ADD_DATE attribute immediately after the url. I tried replacing (
ADD.*) with ( .*), which I thought would match everything up to the ">":
$lines[]=preg_replace("{(<A HREF=".*")( .*)(>.*</A>)}","13", $line);

For some reason, this does not find a match. Since " ADD" is the same as
..*, I don't understand why I need the explicit " ADD".

Creating CSR With Multiple Values For Attributes
I'm trying to get PHP to generate a CSR in which I need the
organizationalUnitName attribute/field to have multiple values.

In the openssl.cnf file when generating the CSR with the "openssl req"
command line, all I need is to include stanza such as:
0.organizationalUnitName = Level 0 OU
1.organizationalUnitName = Level 1 OU
....
n.organizationalUnitName = Level N OU

I hoped that for PHP, I just needed to build an array looking like
dn_array = array(
"0.organizationalUnitName" ="Level 0 OU"
"1.organizationalUnitName" ="Level 1 OU"
....
);

But what I get in the PHP errorlog at the openssl_csr_new($dn_array,
....) call is a:
"dn: 0.organizationalUnitName is not a recognized name" message and so
on for every multi-valued attribute...

Any one ever succedeed in getting openssl_csr_new to do that stuff ?

DOM : Special Chars (entities) In Attributes
I currently use the DOM from PHP5 to create XHTML documents.
I have a problem with entities. I would like to create a node:

<input id="place" value="café rouge">

To do that I simply create the node with createElement, and then:

$node -> setAttribute ("value", $val);

If I set $val = "café rouge", the saveXML causes PHP to fail with an
error message. The accentuated character seems to be a problem.
If I set $val = "caf&eacute; rouge", saveXML automatically replaces
the & with &amp; and that's not what I expect either.

How To Parse-print Attributes From XML Document
I have a working XML parser and now want to print some of the attributes,
I want to pull into an array the type and qualifier" attributes from "Screening":

<Screening type="developer" qualifier="home">

the how can I do that ?

Here is a piece of my XML doc:

<Screenings>
<Screening type="developer" qualifier="home">
<ScreeningResults type="result" mediaType="structured" resultType="report">
<Status>YES RECORD</Status>
<Region>NC</Region>
<County>UNION</County>

Here is a piece of my parser:

............

How To Replace Special HTML Tags With Attributes
I'm working with XML and sometimes it's necessary to use temporary tags, that should be replaced before showing the source. How can I delete these tags?

I assume, that I require preg_replace, but I don't know how to do it. Let's say I want to replace the <iteration ... > and the </iteration> tag from the following HTML code:
PHP Code:

Parsing String Of HTML Attributes Into Key/value Pairs?
I'm working on a project that requires a certain "parsing" functionality... Before I set down to coding this myself, I thought I'd ask in the community if anyone already has available a PHP function or routine that can parse a string of HTML-style attributes into key/value pairs?

For example, an input string (attribute list) might be something like this, as would be applied to an INPUT tag: type="text" name=firstname size=10 maxlength="20"

And the returned result of parsing this string would be something similar to the following array: PHP Code:

Simplexml And Attributes With A Namespace In Front. How Do You Getthe Attribute?
Here's a bit of xml code that works.

<?php

$string =
"<?xml version="1.0" standalone="yes"?>
<world>
<people xmlns:ss="http://crap">
<person id="5">John Doe</person>
<person id="2">Susie Q. Public</person>
</people>
</world>";

$xml = simplexml_load_string($string);
print "<pre>";
print_r($xml);
print "</pre>";

foreach($xml->people->person as $p)
foreach($p->attributes() as $a =$b)
{
print "$a =$b<br />";
}

// prints out
// id =5
// id =2
?>

Now what if I change the first person to this
<person ss:id="5">John Doe</person>

Anyone know how to get the id?

This is a question that is pertinent to an excel .xml file as
you'll get lines like this
<Cell ss:Index="3">stuff</Cell>

btw: there is a guide on ibm that tells you how to do this with php
and dom. I'm just wondering if there's a way to do it with simplexml.

Regex Pattern To Return Xhtml Tag Attributes As Array
Is it possible to write a pattern to match a xhtml tag with indeterminate number of attributes and return these attributes as array with attribute name as key and value as value? PHP Code:

Strip_tags Error - Handling All HTML Entities And Attributes
I have the following code to strip HTML tags from a database record: PHP Code:

Wnat To Embed Full HTML Page In Email, But Migrating Style From Css Files To Element Style Attributes
My web pages of course use css files, but Webmail services require
style to be in element style attributes.

How do I convert a standard HTML page to HTML suitable for delivery to
webmail services?

Perhaps another way to ask the question is:

How to I walk the DOM and for every element, for every style, set the
element's style attribute to the values that are looked up in the css
file in normal rendering.

Anyone know of any tools, or examples to do this?

DOMDocument Thinks "<html></html>" Has Two ChildNodes?
I'm trying to mess around with PHP5's DOM functions and have run into
something that confuses me:

<?php
$dom = new DOMDocument();
$dom->loadHTML('<html></html>');

echo $dom->childNodes->length;
?>

Why is the output 2? Shouldn't it be 1?


Copyright © 2005-08 www.BigResource.com, All rights reserved