[mapguide-users] Modifying SymbolDefinition programmatically

psciga scigalla at battefeld.com
Wed May 13 11:54:50 EDT 2009


Jackie,

thank you very much:jumping:! The following code runs, but with one
exception. I'm loosing the formatting in XML viewer.

Maybe somone have the same problem, here a code snippet. It replaces the
Default Value for ROTATION parameter with a database field "Winkel". I know,
it's very straightforward (sorry I'm not a programmer) but it runs:

$resourceID = new MgResourceIdentifier("Library://acadblocktest/import/");
$byteReader = $resourceService->EnumerateResources($resourceID, -1, "");
$XmlSym = $byteReader->ToString();
$SymDomDoc = DOMDocument::loadXML($XmlSym);
$Spath = new DOMXPath($SymDomDoc);
$Squery = '//ResourceDocument/ResourceId';
$Snodes = $Spath->query($Squery);
foreach ($Snodes as $Snode)
{
   	    $Sname = $Snode->nodeValue;
	    echo "$Sname<p>";
		$resourceID = new MgResourceIdentifier($Sname);
		$byteReader = $resourceService->GetResourceContent($resourceID);
		$Xml = $byteReader->ToString();
		$LDomDoc = DOMDocument::loadXML($Xml);
		echo "DomDoc erzeugt<p>";
		print $LDomDoc->saveXML();
		echo "<p>";
		$I = -1;//zählt die gefundenen Elemente
		$xpath = new DOMXPath($LDomDoc);
		$query = '//ParameterDefinition/Parameter/Identifier';

		$nodes = $xpath->query($query);
		foreach ($nodes as $node )
		{
		  $Ident = $node->nodeValue;
		  echo "$Ident<p>";
		  $I = $I + 1;
		  if($Ident == "ROTATION")
		  {
		   	  $Pos = $I;
			  echo "Position: $I<p>";
		  }
		}
		//jetzt Ausgabe des zugehörigen DefaultValue
		$Parameter = $LDomDoc->getElementsByTagName("DefaultValue")->item($I);
		$Winkel = $Parameter->nodeValue;
		echo "alter Winkel: $Winkel<p>";
		//und hier wird dem NodeValue der neue Wert zugewiesen
		$Parameter->nodeValue = "Winkel";
		$updatedXml = $LDomDoc->saveXML();
		$byteSource = new MgByteSource($updatedXml, strlen($updatedXml));
		$byteSource->SetMimeType(MgMimeType::Xml);
		$resourceId = new MgResourceIdentifier($Sname);
		$resourceService->SetResource($resourceId, $byteSource->GetReader(),
null);
}

Thanks against.

Regards - Peter



Jackie Ng wrote:
> 
> I don't know much about Symbol Definitions, but all resources in mapguide
> (including Symbol Definitions) are XML data.
> 
> So you could use the Resource Service APIs to get the resource content,
> edit the xml content (with your XML access library/api of choice) and save
> back the changes. This can be done with any resource.
> 
> - Jackie
> 
> 
> psciga wrote:
>> 
>> Hello,
>> 
>> can you tell me please, how to modify the symbol definition with php?
>> 
>> Following background:
>> 
>> In AutoCAD I have several hundred blocks. The import into MGOS 2 via MG
>> Studio 2009 works fine. The once problem is, that the parameter for
>> ROTATION
>> have a DefaultValue = 0. This default value I want to replace with a
>> field
>> name "winkel" from the MySQL database. It is easy to do this by hand for
>> some symbols, but with for 657 symbol definitions I become crazy  ;-) .
>> 
>> How can I replace this default value using php?
>> 
>> Thanks in advance.
>> 
>> Regards - Peter
>> 
> 
> 

-- 
View this message in context: http://n2.nabble.com/Modifying-SymbolDefinition-programmatically-tp2879871p2884723.html
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list