Can PHP edit parts/nodes of XML?

akashj
akashj used Ask the Experts™
on
HI all,
I am after a solution in order to be able to modify/edit XML nodes/sections via a PHP form.
The form would have several text boxes and when filled in/submitted, it would REPLACE a certain value in the XML.

The XML is initially extracted from a SQL Database table where it is stored as a blob I assume...

The XML itself is actually a Cognos report and I need maximum/minimum values changes on a Gauge chart.  Annoyingly, this is a cognos limitation whereby it cannot be linked to a value in a database table and so I need to modify this 24 times a day everyday manually.

What I want is to create a form which is tied to these maximum/minimum values so that it is easy to enter in a textbox and the report gets modified accordingly.
Once the submit is hit, I can then "update" the database table with the complete XML with the modifications that the form did.

I hope this makes sense!
Please see in the code section the type of XML it would be tied to

The solution would have to be to edit the value in <gaugeNumericalAxis max="8962"> (in this case 8692)
WHERE  refQuery="Query1

Then for Dial 2, it would be the same but for refQuery="Query2

etc etc
showTooltips="true" maxHotspots="10000" refQuery="Query1" name="Gauge Chart1">
<axisTitle refQuery="Query1">
<style>
<defaultStyles>
<defaultStyle refStyle="at"/>
</defaultStyles>
</style>
</axisTitle>
<gaugeNumericalAxis max="8962">
<gridlines color="#cccccc"/>
</gaugeNumericalAxis>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016

Commented:
XML would probably be stored as TEXT, right?

Can you show us where you are on trying to code this yourself?  Getting a form to send input to PHP is one question, substituting the input form data into the XML string is another question, updating the data base with the modified string is another question - not quite sure where to start until you show us where you are right now.

Thanks and regards, ~Ray

Author

Commented:
Thanks for the reply
OK I'll try and answer the questions but it is a bit difficult explaining this...

Firstly, nothing has been coded at all.  My thinking was to do this via PHP somehow and link it but here would be the steps:

XML would be stored as text - correct.
Would it help if I attached the actual "report" which is in XML?
The way it works is you design the report in the tool (cognos) and it is stored in as XML.  You can test this by using an option to "copy report specification to clipboard" which when pasted in notepad, is in XML.  Pasting this back into the Cognos tool opens this report.

I managed to find out the table the report is stored in which is in one row and under one specific column.
This will be attached below however, if you simply right click and copy the "text" within the column, it is the same as extracting it via cognos.  Pasting this into cognos again opens up the report.

So now that we know that it is in a SQL table ...
My thinking is:
1. Connect to the database
2. Connect to the table and use a select query to the exactly point of where it is stored.  This is via an ID for that row.
3. This is where I now need textboxes to be able to connect to that specific node/s and update in there.

Does this help ?

Most Valuable Expert 2011
Top Expert 2016

Commented:
Yes, it helps and my recommendation is that you either hire a developer (if you need this for a business purpose) or take some classes in HTML, XML, PHP and MySQL so you can get a foundation in these technologies.  You're a couple of college semesters away from fluency in the knowledge needed to do what you describe, but there is nothing in here that cannot be learned given enough time and concentration.  I can recommend two books that would be worthwhile (I own them both).
http://www.sitepoint.com/books/phpmysql4/
http://www.sitepoint.com/books/xml1/

You have a big task ahead of you.  It will be both a challenge and opportunity.  Best of luck with is, ~Ray
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Author

Commented:
Makes sense - I should have said that I am actually good with HTML/PHP/MYSQL just not very good with the XML side -  especially in this context .
Thanks for the advice anyway!  Are you a developer yourself?
Most Valuable Expert 2011
Top Expert 2016

Commented:
Yes, I am a developer, and I may be able to be helpful with the XML part of things.  If you can post the XML (all of it) and tell me a little about what you want to change, I can show you how to do that.

Author

Commented:
Please find attached the file
I have seen your work on here today and am confident you are the person to help out!  I actually noticed you have had similar queries so hopefully it should be a quick one.

I am willing to take this offline with you if it gets to a point that we do need to go via the developer route.

The attached txt file is what is stored in the DB...The parts that need to be in a form/modified are the

1. 6x <gaugeNumericalAxis max=
2. 14x discreteGaugePaletteValue


xml.txt
Most Valuable Expert 2011
Top Expert 2016

Commented:
This does not appear to be valid XML, since it is missing the XML header!  But we can put that on the top, if it turns out to be needed.  Not sure about that - it may be parsed OK anyway.  I will try to isolate one of the parts you need to change and show you how to change it.  Back in a while...
Most Valuable Expert 2011
Top Expert 2016
Commented:
The moving parts of this start at line 187.  The complexity will be evident from the foreach() statement that runs from line 195 - 210.  That shows how you target an object or array inside the XML and change its value.  There are a lot of nesting levels to be dealt with in this document!

I did not try to change "discreteGaugePaletteValue" but the principles will be the same - just the iterator will be different.

Hope that helps, and best of luck with your project. ~Ray
<?php // RAY_temp_akashj.php
error_reporting(E_ALL);
echo "<pre>\n"; // FOR EASY READABILITY OF var_dump()
 
// TEST DATA FROM THE OP
$xml = <<<EOD
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://developer.cognos.com/schemas/report/6.0/" expressionLocale="en-gb">
				<modelPath>/content/package[@name='TEST']/model[@name='model']</modelPath>
				<drillBehavior modelBasedDrillThru="true"/>
				<layouts>
					<layout>
						<reportPages>
							<page name="Page1">
								<style>
									<defaultStyles>
										<defaultStyle refStyle="pg"/>
									</defaultStyles>
								</style>
								<pageBody>
									<style>
										<defaultStyles>
											<defaultStyle refStyle="pb"/>
										</defaultStyles>
									</style>
									<contents><table><style><defaultStyles><defaultStyle refStyle="tb"/></defaultStyles><CSS value="border-collapse:collapse;width:100%"/></style><tableRows><tableRow><tableCells><tableCell><contents>
												<gaugeChart showTooltips="true" maxHotspots="10000" refQuery="Query1" name="Gauge Chart1">
 
														<axisTitle refQuery="Query1">
															<style>
																<defaultStyles>
																	<defaultStyle refStyle="at"/>
																</defaultStyles>
															</style>
														</axisTitle>
														<gaugeNumericalAxis max="12130">
															<gridlines color="#cccccc"/>
														</gaugeNumericalAxis>
														<gaugeLabels>
															<style>
																<defaultStyles>
																	<defaultStyle refStyle="al"/>
																</defaultStyles>
															<CSS value="visibility:hidden"/></style>
														</gaugeLabels>
														<style>
															<defaultStyles>
																<defaultStyle refStyle="ch"/>
															</defaultStyles>
														<CSS value="width:7cm;height:5cm"/></style>
														<indicators><chartNodes><chartNode><chartNodeMembers><chartNodeMember refDataItem="Actuals"><chartContents><chartTextItem><dataSource><memberCaption/></dataSource></chartTextItem></chartContents></chartNodeMember></chartNodeMembers></chartNode><chartNode><chartNodeMembers><chartNodeMember refDataItem="Budget"><chartContents><chartTextItem><dataSource><memberCaption/></dataSource></chartTextItem></chartContents></chartNodeMember></chartNodeMembers></chartNode></chartNodes></indicators><chartPalette><chartColor value="#000000"/><chartColor value="silver"/><chartColor value="#993333"/><chartColor value="#CCCC00"/><chartColor value="#336633"/><chartColor value="#6699CC"/><chartColor value="#FF0033"/><chartColor value="#FF6633"/><chartColor value="#CC0099"/><chartColor value="#66CC00"/><chartColor value="#0033FF"/><chartColor value="#6666FF"/><chartColor value="#9900FF"/><chartColor value="#339966"/><chartColor value="#FFCC00"/><chartColor value="#6633CC"/><chartColor value="#999999"/></chartPalette><gaugePalette percentValues="true"><discreteGaugePalette><discreteGaugePaletteEntry discreteGaugePaletteColor="#FF0000" discreteGaugePaletteValue="35"/><discreteGaugePaletteEntry discreteGaugePaletteColor="#FFFF00" discreteGaugePaletteValue="43"/><discreteGaugePaletteEntry discreteGaugePaletteColor="#00FF00" discreteGaugePaletteValue="57"/><discreteGaugePaletteEntry discreteGaugePaletteColor="#FFFF00" discreteGaugePaletteValue="65"/><discreteGaugePaletteEntry discreteGaugePaletteColor="#FF0000"/></discreteGaugePalette></gaugePalette></gaugeChart>
												</contents><style><CSS value="text-align:center;vertical-align:top;width:25%;height:25%"/></style></tableCell><tableCell><contents>
												<gaugeChart showTooltips="true" maxHotspots="10000" refQuery="Query3" name="Gauge Chart3">
 
														<axisTitle refQuery="Query3">
															<style>
																<defaultStyles>
																	<defaultStyle refStyle="at"/>
																</defaultStyles>
															</style>
														</axisTitle>
														<gaugeNumericalAxis max="46">
															<gridlines color="#cccccc"/>
														<style><dataFormat><numberFormat decimalSize="0"/></dataFormat></style></gaugeNumericalAxis>
														<gaugeLabels>
															<style>
																<defaultStyles>
																	<defaultStyle refStyle="al"/>
																</defaultStyles>
															<CSS value="visibility:hidden"/></style>
														</gaugeLabels>
														<style>
															<defaultStyles>
																<defaultStyle refStyle="ch"/>
															</defaultStyles>
														<CSS value="width:7cm;height:5cm"/></style>
														<indicators><chartNodes><chartNode><chartNodeMembers><chartNodeMember refDataItem="Actuals"><chartContents><chartTextItem><dataSource><memberCaption/></dataSource></chartTextItem></chartContents><style><dataFormat><numberFormat decimalSize="0"/></dataFormat></style></chartNodeMember></chartNodeMembers></chartNode><chartNode><chartNodeMembers><chartNodeMember refDataItem="Budget"><chartContents><chartTextItem><dataSource><memberCaption/></dataSource></chartTextItem></chartContents></chartNodeMember></chartNodeMembers></chartNode></chartNodes></indicators><chartPalette><chartColor value="#000000"/><chartColor value="silver"/><chartColor value="#993333"/><chartColor value="#CCCC00"/><chartColor value="#336633"/><chartColor value="#6699CC"/><chartColor value="#FF0033"/><chartColor value="#FF6633"/><chartColor value="#CC0099"/><chartColor value="#66CC00"/><chartColor value="#0033FF"/><chartColor value="#6666FF"/><chartColor value="#9900FF"/><chartColor value="#339966"/><chartColor value="#FFCC00"/><chartColor value="#6633CC"/><chartColor value="#999999"/></chartPalette><gaugePalette percentValues="false"><discreteGaugePalette><discreteGaugePaletteEntry discreteGaugePaletteColor="#00FF00" discreteGaugePaletteValue="20"/><discreteGaugePaletteEntry discreteGaugePaletteColor="#FFFF00" discreteGaugePaletteValue="30"/><discreteGaugePaletteEntry discreteGaugePaletteColor="#FF0000"/></discreteGaugePalette></gaugePalette></gaugeChart></contents><style><CSS value="text-align:center;vertical-align:top;width:25%;height:25%"/></style></tableCell><tableCell><contents><gaugeChart showTooltips="true" maxHotspots="10000" refQuery="Query2" name="Gauge Chart2">
 
														<axisTitle refQuery="Query2">
															<style>
																<defaultStyles>
																	<defaultStyle refStyle="at"/>
																</defaultStyles>
															</style>
														</axisTitle>
														<gaugeNumericalAxis max="4502">
															<gridlines color="#cccccc"/>
														</gaugeNumericalAxis>
														<gaugeLabels>
															<style>
																<defaultStyles>
																	<defaultStyle refStyle="al"/>
																</defaultStyles>
															<CSS value="visibility:hidden"/></style>
														</gaugeLabels>
														<style>
															<defaultStyles>
																<defaultStyle refStyle="ch"/>
															</defaultStyles>
														<CSS value="width:7cm;height:5cm"/></style>
														<indicators><chartNodes><chartNode><chartNodeMembers><chartNodeMember refDataItem="Actuals"><chartContents><chartTextItem><dataSource><memberCaption/></dataSource></chartTextItem></chartContents></chartNodeMember></chartNodeMembers></chartNode><chartNode><chartNodeMembers><chartNodeMember refDataItem="Budget"><chartContents><chartTextItem><dataSource><memberCaption/></dataSource></chartTextItem></chartContents></chartNodeMember></chartNodeMembers></chartNode></chartNodes></indicators><chartPalette><chartColor value="#000000"/><chartColor value="silver"/><chartColor value="#993333"/><chartColor value="#CCCC00"/><chartColor value="#336633"/><chartColor value="#6699CC"/><chartColor value="#FF0033"/><chartColor value="#FF6633"/><chartColor value="#CC0099"/><chartColor value="#66CC00"/><chartColor value="#0033FF"/><chartColor value="#6666FF"/><chartColor value="#9900FF"/><chartColor value="#339966"/><chartColor value="#FFCC00"/><chartColor value="#6633CC"/><chartColor value="#999999"/></chartPalette><gaugePalette percentValues="false"><discreteGaugePalette><discreteGaugePaletteEntry discreteGaugePaletteColor="#FF0000" discreteGaugePaletteValue="1997"/><discreteGaugePaletteEntry discreteGaugePaletteColor="#FFFF00" discreteGaugePaletteValue="2102"/><discreteGaugePaletteEntry discreteGaugePaletteColor="#00FF00"/></discreteGaugePalette></gaugePalette></gaugeChart>
												</contents><style><CSS value="text-align:center;vertical-align:top;width:25%;height:25%"/></style></tableCell></tableCells></tableRow><tableRow><tableCells><tableCell><contents><gaugeChart showTooltips="true" maxHotspots="10000" refQuery="Query4" name="Gauge Chart4">
 
														<axisTitle refQuery="Query4">
															<style>
																<defaultStyles>
																	<defaultStyle refStyle="at"/>
																</defaultStyles>
															</style>
														</axisTitle>
														<gaugeNumericalAxis max="8270">
															<gridlines color="#cccccc"/>
														</gaugeNumericalAxis>
														<gaugeLabels>
															<style>
																<defaultStyles>
																	<defaultStyle refStyle="al"/>
																</defaultStyles>
															<CSS value="visibility:hidden"/></style>
														</gaugeLabels>
														<style>
															<defaultStyles>
																<defaultStyle refStyle="ch"/>
															</defaultStyles>
														<CSS value="width:7cm;height:5cm"/></style>
														<indicators><chartNodes><chartNode><chartNodeMembers><chartNodeMember refDataItem="Actuals"><chartContents><chartTextItem><dataSource><memberCaption/></dataSource></chartTextItem></chartContents></chartNodeMember></chartNodeMembers></chartNode><chartNode><chartNodeMembers><chartNodeMember refDataItem="Budget"><chartContents><chartTextItem><dataSource><memberCaption/></dataSource></chartTextItem></chartContents></chartNodeMember></chartNodeMembers></chartNode></chartNodes></indicators><chartPalette><chartColor value="#000000"/><chartColor value="silver"/><chartColor value="#993333"/><chartColor value="#CCCC00"/><chartColor value="#336633"/><chartColor value="#6699CC"/><chartColor value="#FF0033"/><chartColor value="#FF6633"/><chartColor value="#CC0099"/><chartColor value="#66CC00"/><chartColor value="#0033FF"/><chartColor value="#6666FF"/><chartColor value="#9900FF"/><chartColor value="#339966"/><chartColor value="#FFCC00"/><chartColor value="#6633CC"/><chartColor value="#999999"/></chartPalette><gaugePalette percentValues="false"><discreteGaugePalette><discreteGaugePaletteEntry discreteGaugePaletteColor="#FF0000" discreteGaugePaletteValue="2894.5"/><discreteGaugePaletteEntry discreteGaugePaletteColor="#FFFF00" discreteGaugePaletteValue="3514.75"/><discreteGaugePaletteEntry discreteGaugePaletteColor="#00FF00"/></discreteGaugePalette></gaugePalette></gaugeChart>
												</contents><style><CSS value="text-align:center;width:25%;height:25%"/></style></tableCell><tableCell><contents>
												<gaugeChart showTooltips="true" maxHotspots="10000" refQuery="Query6" name="Gauge Chart6">
 
														<axisTitle refQuery="Query6">
															<style>
																<defaultStyles>
																	<defaultStyle refStyle="at"/>
																</defaultStyles>
															</style>
														</axisTitle>
														<gaugeNumericalAxis max="1">
															<gridlines color="#cccccc"/>
														<style><dataFormat><percentFormat percentSymbol="%"/></dataFormat></style></gaugeNumericalAxis>
														<gaugeLabels>
															<style>
																<defaultStyles>
																	<defaultStyle refStyle="al"/>
																</defaultStyles>
															<CSS value="visibility:hidden"/></style>
														</gaugeLabels>
														<style>
															<defaultStyles>
																<defaultStyle refStyle="ch"/>
															</defaultStyles>
														<CSS value="width:7cm;height:5cm"/></style>
														<indicators><chartNodes><chartNode><chartNodeMembers><chartNodeMember refDataItem="Actuals"><chartContents><chartTextItem><dataSource><memberCaption/></dataSource></chartTextItem></chartContents></chartNodeMember></chartNodeMembers></chartNode></chartNodes></indicators><chartPalette><chartColor value="#000000"/><chartColor value="silver"/><chartColor value="#993333"/><chartColor value="#CCCC00"/><chartColor value="#336633"/><chartColor value="#6699CC"/><chartColor value="#FF0033"/><chartColor value="#FF6633"/><chartColor value="#CC0099"/><chartColor value="#66CC00"/><chartColor value="#0033FF"/><chartColor value="#6666FF"/><chartColor value="#9900FF"/><chartColor value="#339966"/><chartColor value="#FFCC00"/><chartColor value="#6633CC"/><chartColor value="#999999"/></chartPalette><gaugePalette percentValues="true"><continuousChartPalette><continuousChartPaletteEntry paletteEntryValue="0" paletteEntryColor="#FF0000"/><continuousChartPaletteEntry paletteEntryValue="50" paletteEntryColor="#FFFF00"/><continuousChartPaletteEntry paletteEntryValue="100" paletteEntryColor="#00FF00"/></continuousChartPalette></gaugePalette></gaugeChart></contents><style><CSS value="text-align:center;width:25%;height:25%"/></style></tableCell><tableCell><contents>
												<gaugeChart showTooltips="true" maxHotspots="10000" refQuery="Query5" name="Gauge Chart5">
 
														<axisTitle refQuery="Query5">
															<style>
																<defaultStyles>
																	<defaultStyle refStyle="at"/>
																</defaultStyles>
															</style>
														</axisTitle>
														<gaugeNumericalAxis max="6000">
															<gridlines color="#cccccc"/>
														</gaugeNumericalAxis>
														<gaugeLabels>
															<style>
																<defaultStyles>
																	<defaultStyle refStyle="al"/>
																</defaultStyles>
															<CSS value="visibility:hidden"/></style>
														</gaugeLabels>
														<style>
															<defaultStyles>
																<defaultStyle refStyle="ch"/>
															</defaultStyles>
														<CSS value="width:7cm;height:5cm"/></style>
														<indicators><chartNodes><chartNode><chartNodeMembers><chartNodeMember refDataItem="Actuals"><chartContents><chartTextItem><dataSource><memberCaption/></dataSource></chartTextItem></chartContents></chartNodeMember></chartNodeMembers></chartNode><chartNode><chartNodeMembers><chartNodeMember refDataItem="Budget"><chartContents><chartTextItem><dataSource><memberCaption/></dataSource></chartTextItem></chartContents></chartNodeMember></chartNodeMembers></chartNode></chartNodes></indicators><chartPalette><chartColor value="#000000"/><chartColor value="silver"/><chartColor value="#993333"/><chartColor value="#CCCC00"/><chartColor value="#336633"/><chartColor value="#6699CC"/><chartColor value="#FF0033"/><chartColor value="#FF6633"/><chartColor value="#CC0099"/><chartColor value="#66CC00"/><chartColor value="#0033FF"/><chartColor value="#6666FF"/><chartColor value="#9900FF"/><chartColor value="#339966"/><chartColor value="#FFCC00"/><chartColor value="#6633CC"/><chartColor value="#999999"/></chartPalette><gaugePalette percentValues="false"><discreteGaugePalette><discreteGaugePaletteEntry discreteGaugePaletteColor="#00FF00" discreteGaugePaletteValue="3542"/><discreteGaugePaletteEntry discreteGaugePaletteColor="#FFFF00" discreteGaugePaletteValue="3719"/><discreteGaugePaletteEntry discreteGaugePaletteColor="#FF0000"/></discreteGaugePalette></gaugePalette></gaugeChart>
												</contents><style><CSS value="text-align:center;width:25%;height:25%"/></style></tableCell></tableCells></tableRow></tableRows></table></contents>
								</pageBody>
							</page>
						</reportPages>
					</layout>
				</layouts>
			<XMLAttributes><XMLAttribute name="RS_CreateExtendedDataItems" value="true" output="no"/><XMLAttribute name="listSeparator" value="," output="no"/></XMLAttributes><queries><query name="Query1"><source><model/></source><selection><dataItem name="FactItem" aggregate="none" rollupAggregate="none"><expression>[BusinessLayer].[ExecKPIs].[FactItem]</expression></dataItem><dataItem name="Actuals" aggregate="total"><expression>[BusinessLayer].[ExecKPIs].[Actuals]</expression></dataItem><dataItem name="Budget" aggregate="total"><expression>[BusinessLayer].[ExecKPIs].[Budget]</expression></dataItem><dataItem name="Above"><expression>[Budget] * 1.05</expression></dataItem><dataItem name="Below"><expression>[Budget] * 0.95</expression></dataItem></selection><detailFilters><detailFilter use="required" postAutoAggregation="false"><filterExpression>[FactItem] = 'Inbound customer call volumes'</filterExpression></detailFilter></detailFilters><queryHints><localCache value="false"/></queryHints></query><query name="Query2"><source><model/></source><selection><dataItem name="FactItem" aggregate="none" rollupAggregate="none"><expression>[BusinessLayer].[ExecKPIs].[FactItem]</expression></dataItem><dataItem name="Actuals" aggregate="total"><expression>[BusinessLayer].[ExecKPIs].[Actuals]</expression></dataItem><dataItem name="Budget" aggregate="total"><expression>[BusinessLayer].[ExecKPIs].[Budget]</expression></dataItem></selection><detailFilters><detailFilter use="required" postAutoAggregation="false"><filterExpression>[FactItem] = 'Gross daily sales'</filterExpression></detailFilter></detailFilters><queryHints><localCache value="false"/></queryHints></query><query name="Query3"><source><model/></source><selection><dataItem name="FactItem" aggregate="none" rollupAggregate="none"><expression>[BusinessLayer].[ExecKPIs].[FactItem]</expression></dataItem><dataItem name="Actuals" aggregate="total"><expression>[BusinessLayer].[ExecKPIs].[Actuals]</expression></dataItem><dataItem name="Budget" aggregate="total"><expression>[BusinessLayer].[ExecKPIs].[Budget]</expression></dataItem></selection><detailFilters><detailFilter use="required" postAutoAggregation="false"><filterExpression>[FactItem] = 'Wait times on CTI calls'</filterExpression></detailFilter></detailFilters><queryHints><localCache value="false"/></queryHints></query><query name="Query4"><source><model/></source><selection><dataItem name="FactItem" aggregate="none" rollupAggregate="none"><expression>[BusinessLayer].[ExecKPIs].[FactItem]</expression></dataItem><dataItem name="Actuals" aggregate="total"><expression>[BusinessLayer].[ExecKPIs].[Actuals]</expression></dataItem><dataItem name="Budget" aggregate="total"><expression>[BusinessLayer].[ExecKPIs].[Budget]</expression></dataItem></selection><detailFilters><detailFilter use="required" postAutoAggregation="false"><filterExpression>[FactItem] = 'Clicks on sky.com/hd'</filterExpression></detailFilter></detailFilters><queryHints><localCache value="false"/></queryHints></query><query name="Query5"><source><model/></source><selection><dataItem name="FactItem" aggregate="none" rollupAggregate="none"><expression>[BusinessLayer].[ExecKPIs].[FactItem]</expression></dataItem><dataItem name="Actuals" aggregate="total"><expression>[BusinessLayer].[ExecKPIs].[Actuals]</expression></dataItem><dataItem name="Budget" aggregate="total"><expression>[BusinessLayer].[ExecKPIs].[Budget]</expression></dataItem></selection><detailFilters><detailFilter use="required" postAutoAggregation="false"><filterExpression>[FactItem] = 'Gross daily churn'</filterExpression></detailFilter></detailFilters><queryHints><localCache value="false"/></queryHints></query><query name="Query6"><source><model/></source><selection><dataItem name="Actuals" aggregate="total"><expression>[BusinessLayer].[ExecKPIs].[Actuals] / 100</expression></dataItem><dataItem name="FactItem" aggregate="none" rollupAggregate="none"><expression>[BusinessLayer].[ExecKPIs].[FactItem]</expression></dataItem></selection><detailFilters><detailFilter use="required" postAutoAggregation="false"><filterExpression>[FactItem]='% of installs completed'</filterExpression></detailFilter></detailFilters><queryHints><localCache value="false"/></queryHints></query></queries></report>
EOD;
 
// MAKE AN OBJECT FROM THE XML
$obj = SimpleXML_Load_String($xml);
 
// ACTIVATE THIS TO VISUALIZE THE INITIAL OBJECT
// var_dump($obj);
 
// ITERATE OVER THE OBJECT - DRILL INTO THE OBJECT AT THE APPROPRIATE LEVEL
foreach ($obj->
          layouts->
          layout->
          reportPages->
          page->
          pageBody->
          contents->
          table->
          tableRows->
          tableRow->
          tableCells->
          tableCell->
          contents->
          gaugeChart->
          gaugeNumericalAxis
 
          as $thing)
{
    // SHOW THING BEFORE AND AFTER WE MAKE THE CHANGES
    echo "\nBEFORE:\n";
    var_dump($thing);
 
    $thing["max"] = 'CHANGED_VALUE';
 
    echo "\nAFTER:\n";
    var_dump($thing);
}
 
// CREATE THE NEW XML STRING FROM THE MODIFIED OBJECT
$new = $obj->asXML();
 
// SHOW WHAT WE CREATED - SEARCH THE OUTPUT PAGE FOR 'CHANGED_VALUE'
echo "\nNEW XML:\n";
echo htmlentities($new);

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial