Jump to content

Asp Or Php


Recommended Posts

Sorry about not following everything that's been said in this topic... but that's basically why I feel its ugly:1. It starts of as a simple question2. The answer is completely misunderstood (at least at first)3. The topic strays away at ASP/PHP/XML(/miscellanious?) issues4. The topic starts to get generic by introducing the W3Schools tutorials into the conversationIn short: it lacks focus.... or maybe it's just me and my damaged attention span.Anyway, what was the issue again? Opening, editing and saving an XML file? That is, how to do it? In a word - DOM. That's what I'd use, that's what most powerful, and that's what is most easily migratable between ASP and PHP.Example:

<?php$filename = 'test.xml';$dom = new DOMDocumet;$dom->load($filename);//Do editings here with the DOM API$dom->save($filename);?>

Equivalent skeleton in ASP:

<%Dim dom, filenameset filename = server.MapPath("tool.xml")set dom = Server.CreateObject("Microsoft.XMLDOM")dom.load(filename)'Do editings here with the DOM APIdom.save(filename)%>

(not sure if the ASP one will work though - it's just something I put out from the W3Schools example)DOM is similar to SimpleXML in that it's an API for processing XML documents. It has some unique abilities that are most noticeable when you deal with namespaced documents. It's perhaps not as simple as SimpleXML at first, but once you get used to it (and if you use JavaScript, you basically HAVE to get used to DOM), it becomes a breeze. The best part is that, like I just said, it's easily portable between languages (JavaScript, PHP, .NET, you name it). The only thing you really need to change is the syntax notation for accessing and creating objects (in the PHP to ASP case, that's like changing "->" to ".").The exact thing you do in the commented section depends entirely on what you want to do. For example, if you want to change the value of specific node(s), you need to select it (or them) somehow, and then edit it (or loop over the resulting collection, and edit each one). You can traverse DOM either as objects, or with XPath. A simple example with XPath in PHP editing a single node:

$xpath = new DOMXPath($dom);$xpath->query('//field/*[3]/@at')->item(0)->nodeValue = "New Value";

The equivalent with DOM traversal in PHP:

$dom->getElementsByTagName('field')->item(0)->childNodes->item(2)->getAttributeNode('at')->nodeValue = "New Value";

In either case, right before the last "->nodeValue", you're really trying to reach the node you'll be altering, copying or whatever.Looping over the resulting collection when you want to edit mutiple nodes is unavoidable. The DOM environment (JavaScript, PHP, ASP.NET, etc.) can't know by itself which nodes you want to alter, and whether you really want to alter all of them in the exact same fashion. After all, what if you wanted a slighly different modification for each matched element (like say, a counter? each matched element's value is going to be a number from 0 to the number of matched nodes). The same applies for SimpleXML AFAIK.There's no such thing as a universal XML editior. XML is made to be morphed from one dialect to another. You may have a generic XML editor (i.e. an XML text editor), you may have an RSS editor, you may have an SVG editor, but you can't have an RSS editor work as if the document is SVG or vise versa. The whole point of XML is to have a common base (XML and DOM) for otherwise specialized tasks like news (RSS), graphics (SVG), document layouts (XHTML), etc.As for XSLT, the XSL extension is simple, in my opinion at least... once you get it running that is. Before I learned how to enable PHP extensions, it was a big hurdle for me, but once I successfully launched it once, taking it's full potential was a matter of days (and the only reason it wasn't "hours" or "minutes" was because I didn't had enough use cases to use it up to its full potential). In fact, I like it so much I actually have another API "spin-off" myself, that enables PHP to execute XSLT 2.0 by using SAXON or AltovaXML... that is, it wraps their inconvinient interfaces into an API similar to the PHP XSL API. See my signature if you're interested, but be warned - it's much slower than the native PHP XSLT processor, so if you only need the XSLT 1.0 features - go for the native.The examples I gave in my last post are the examples missing in W3Schools. Especially the one on the page for transformToXML().

Edited by boen_robot
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...