473,382 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

php and xml DomDocument

Hi Ng,
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 ...
Any suggestions?
class Article extends DomDocument
{
public function __contruct()
{
parent::__contruct('1.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-
Datei
anhängen kann?
}
}

Apr 3 '07 #1
3 7294
On 2007-04-03 17-39-53, ib*****@googlemail.com wrote:
Any suggestions?
//hier bekomme ich den Fehler, obwohl es den Tag "arcticles" gibt
//andere Ideen wie ich einen neuen Text in einer bestehender xml-Datei anhängen kann?
Yup. Tanslate your comments as well next time. ;)

For people unable to understand Germen:
// here I'm getting the error, although "articles" exists.
// any other ideas on how to append new text to an existing xml file?

Grüsse
Apr 3 '07 #2
ib*****@googlemail.com wrote:
Hi Ng,
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 ...
Any suggestions?
class Article extends DomDocument
{
public function __contruct()
{
parent::__contruct('1.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-
Datei
anhängen kann?
}
}
Where are you loading your XML file, and what does it look like?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 3 '07 #3
On 3 Apr 2007 08:39:53 -0700, ib*****@googlemail.com wrote:
>Hi Ng,
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 ...
Any suggestions?
class Article extends DomDocument
{
public function __contruct()
What's your actual code, or is this typo in your real code as well?
> {
parent::__contruct('1.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
"arcticles" or "articles" ?
> $channels->item(0)->appendChild($newItem);
//andere Ideen wie ich einen neuen Text in einer bestehender xml-
Datei
anhängen kann?
}
}
--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Apr 3 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Colin McGuigan | last post by:
Shorter: 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. ...
1
by: Mini Mouse | last post by:
Hiya folks, 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...
1
by: K. Wilder | last post by:
I've made an ASP form page that is executed via a Javascript function. There's a javascript function that builds an XML object with the form values. But in some browers it seems to fail on the...
3
by: hb | last post by:
Hi, I need to use MSXML2.DOMDocument in my ASP page. The following is my code: xml.asp: ===== <% dim sx sx="<root><a>text1</a><b>text2</b></root>" dim xd
3
by: Dean Slindee | last post by:
Newbie question: Any easy way to convert a DOMDocument to a System.Xml.Document? Dim DOMDocument As DOMDocument40 to this Dim xmlDoc As System.Xml.XmlDocument Thanks,
0
by: pieV | last post by:
I am using Msxml2.DOMDocument to pull xml fragments from different sibling websites. This works off the net, however during testing on my localhost, it fails if called from an external website....
2
by: Sebastian Araya | last post by:
Hello, 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 =...
0
by: paulroskilly | last post by:
Hi, 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...
2
by: J˙Gius³ vs ::NRG::ius | last post by:
Hi all. I have this script ----------------------------------------------------------- <?php $doc = new DOMDocument(); $doc->load('books.xml'); echo $doc->saveXML(); ?>
1
by: malayappa | last post by:
Hi All here is the error what i m getting Warning: domdocument::domdocument() expects parameter 2 to be long, string given in D:\Program Files\Apache Software...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.