I want to replace innertext of a XML node my XML file named test.xml is
<?xml version="1.0" encoding="utf-8"?>
<ads>
<loop>no</loop>
<item>
<description>Description 1</description>
</item>
<item>
<description>Text in item2</description>
</item>
<item>
<description>Let play with this XML</description>
</item>
</ads>
I want to change the value of loop and description tag both,
and it should be saved in test.xml like:
<?xml version="1.0" encoding="utf-8"?>
<ads>
<loop>yes</loop>
<item>
<description>Description Changing Here</description>
</item>
<item>
<description>Changing text in item2</description>
</item>
<item>
<description>We will play later</description>
</item>
</ads>
I tried code in PHP:
<?
$file = "test.xml";
$fp = fopen($file, "rb") or die("cannot open file");
$str = fread($fp, filesize($file));
$dom=new DOMDocument();
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
$dom->loadXML($str) or die("Error");
//$dom->load("items.xml");
$root=$dom->documentElement; // This can differ (I am not sure, it can be only documentElement or documentElement->firstChild or only firstChild)
$loop=$root->getElementsByTagName('loop')->item(0);//->textContent;
//echo $loop;
if(trim($loop->textContent)=='no')
{
echo 'ok';
$root->getElementsByTagName('loop')->item(0)->nodeValue ='yes';
}
echo "<xmp>NEW:\n". $dom->saveXML() ."</xmp>";
?>
I tried only for loop tag.I don't know how to replace nodevalue in description tag.
When I run this page it shows output like:
ok
NEW:
<?xml version="1.0" encoding="utf-8"?>
<ads>
<loop>yes</loop>
<item>
<description>Description 1</description>
</item>
<item>
<description>Changing text in item2</description>
</item>
<item>
<description>Let play with this XML</description>
</item>
</ads>
It gives the value yes in browser but don't save it in test.xml any reason?
I get this error:
Catchable fatal error: Object of class stdClass could not be converted to string
So, my question is, how do I convert an object to a string in PHP? I don't want to serialize it though.
Just a note: the code I use works in PHP 4, but not in PHP 5
Thanks!
Ok, to begin with, this is my code:
HyperSprite::HyperSprite()
{
_view = 0;
}
void HyperSprite::publish(QGraphicsView* view) {
_view = view;
}
void HyperSprite::getKFrame() {
if(_view != 0) {
qDebug()<<(void*)_view;
}
}
Now, if I call HyperSprite::getKFrame() from within main(), I get the output:
0xbf8ffb84
I have a TCP server, which requires this QGraphicsView* variable. So whenever a new connection is made, HyperSprite::getKFrame() is called. However, whenever I make a connection to my server, this is the output:
0x1e425ff
I honestly don't understand this. Shouldn't the value of a member remain same throughout? Why is the pointer value changing? As is obvious, whenever I try to use the _view pointer to access any of its members, a Segmentation Fault occurs. I tried using QSharedPointer, but it also results in the same problem. The data of the QSharedPointer automatically changes. Why is this happening?
Hi
Lets say I have an array with a structure like this:
$arr= Array(
array(
"id"=>"a"
"type">"apple"),
array(
"id"=>"b"),
array(
"id"=>"c"),
array(
"id"=>"c"
"type"=>"banana")
);
now I want to have a foreach loop which fetches all the array elements which have a key in them named "type".
Something like
foreach(all arrays which have type in them as $item)
How would I do that?
many thanks.
I need a text field very similar in behavior to Gxt's NumberField. Unfortunately I am not using Gxt in my application and GWT 2.0 does not have a Numeric text field implementation as yet.
So that currently leaves me with an option to simulate a NumberField by filtering out non-numeric keystrokes using a keyboardHandler.
Is this the the best way to approach the problem? Does anyone here have a better solution/approach in mind?
Thanks in advance :)
Is there anyway I can handle both json and html return types when posting jquery ajax:
For example, this ajax call expects html back
$.ajax({
type: "POST",
url: url
data: data,
dataType: "html",
success: function (response) {
var $html = "<li class='list-item'>" + response + "</li>";
$('#a').prepend($html);
},
error: function (xhr, status, error) {
alert(xhr.statusText);
}
});
but I wanted to modify it so that I can return a json object if there is a model error. so I can do something like this:
success: function (response) {
if (response.Error){
alert(response.Message);
} else {
var $html = "<li class='list-item'>" + response + "</li>";
$('#a').prepend($html);
}
Is this possible?
Hello All,
I'm using BoundsChecker9.1 with visual c++. I have a class
class Sample{
public:
vector(AnotherClass) x;
}. When I run my program the BoundsChecker tool reports all push_back() calls such as S.x.push_back(AnotherClass()) as memory leak.. Wouldn't all the elements in vector x will always be deallocated when the Sample class goes out of scope? If so, any idea about why BoundsChecker is showing them as memory leak?
Consider the following use case
1. User selects a product to purchase on seller's site
2. Clicks on net-banking option and redirected to his bank website
3. Successfully makes the payment.
4. But before the payment gateway redirects him back to seller site the browser crashes.
5. Seller site reports that payment is not recived but the bank reports that payment has been made.
What are the best practices to handle such cases?
Hi all,
My client wants to Migrating their custom developed php project to cake php framework. But, as of now i have only a bit of knowledge in CAKE. can anyone please let me know where do i get started CAKE php. i have already installed CAKE in my system
Hello All,
I have the following piece of snippet
Class Sample
{ Obj_Class1 o1;
Obj_Class2 o2;};
But the size of Obj_Class1 and Obj_Class2 is huge so that the compiler shows a warning "Consider moving some space to heap". I was asked to replace Obj_Class1 o1 with Obj_Class1* o1 = new Obj_Class1(); But I feel that there is no use of making this change as heap allocation will also fail if stack allocation fails. Am I correct? Or does it make sense to make this change ( other than suppressing the compiler warning ).
can any one please let me know the global declaration of php variables..i have seen one among the site like..
for integer start with i, eg: $iItemId
for array start with a, eg: $aItemIds
for string start with s, eg: $sItemName
Consider the following code.
var overlay = new Y.Overlay({
id:'tooltip-tag',
bodyContent:"Loading.....",
xy:[e.target.getX(),e.target.getY()+30]
});
The overlay gets the id as given in attributes. But what if I want to add a class ?
IS there something like:
var overlay = new Y.Overlay({
**class:'tooltip-tag'**,
bodyContent:"Loading.....",
xy:[e.target.getX(),e.target.getY()+30]
});
can any one please let me know is there any way to grab a screen shot of a web page when we pass the URL as parameter. I have a requirement to capture a screen shot of that page when posting a blog.
This i need in php script.
Can any one please let me know the best way to use IF statement in mysql query to show if the "email" field is NULL then it should show as "no email"...
Postcode Telephone Email
----------------------------------------------------------
BS20 0QN 1275373088 no email
BS20 0QN 1275373088 no email
PO9 4HG 023 92474208 [email protected]
SO43 7DS 07801 715200 [email protected]
----------------------------------------------------------
I am maintaining a legacy application which prints product labels on packaging. The format of the label is stored in a INI file. I wanted to know if anyone has any hints about the meaning of this format. I have pasted a snippet here.
{D1531,1000,1501|}
{C|}
{U2;0130|}
{D1531,1000,1501|}
{AX;+000,+000,+00|}
{AY;+05,0|}
{PC000;0922,0555,15,15,H,11,B|}
{RC00;<FE/>LABELTITLE</FE>|}
{PC001;0865,0555,15,15,H,11,B|}
{RC01;<FE/>CURRENT</FE>|}
{PC002;0796,0040,10,10,H,11,B|}
can any one please let me know the main difference between <pubDate> and <dc:date> in feed's structure. also please explain
<dc:date>
<dc:creator>
<dc:....>
<dc:....>
will those be required for building feeds?
Can any one please let me know that, I need to add a column dynamically when executing mysql query
Table: Table1
--------------------------
col1 col2 col3
--------------------------
Test OK Test3
Test OK Test5
Test OK Test6
from the above example i need to introduce "col2" as new column and its value to be as "OK"