Tag Archive for xml

Formulario de Comentario Incrustado en Blogger (Con Correccion)

<p class='comment-footer'> <!-- Segundo que hay en el código -->
<b:if cond='data:post.embedCommentForm'>
<b:include data='Post' name='comment-form'/>
<b:else/>
<b:if cond='data:post.allowComments'>
<a expr:href='data:post.addCommentUrl'
expr:onclick='data:post.addCommentOnclick'>
<data:postCommentMsg/>
</a>
</b:if>
</b:if>

source

Formulario de Comentario Incrustado en Blogger (Con Correccion)

<p class='comment-footer'> <!-- Segundo en el blog -->
<b:if cond='data:post.embedCommentForm'>
<b:include data='Post' name='comment-form'/>
<b:else/>
<b:if cond='data:post.allowComments'>
<a expr:href='data:post.addCommentUrl'
expr:onclock='data:post.addCommentOnclick'>
<data:postCommentMsg/></a>
</b:if>
</b:if>

source

Formulario de Comentario Incrustado en Blogger

<p class='comment-footer'> <!-- Segundo en el blog -->
<b:if cond='data:post.embedCommentForm'>
<b:inclide data='Post' name='comment-form'/>
<b:else/>
<b:if cond='data:post.allowComments'>
<a expr:href='data:post.addCommentUrl'
expr:onclock='data:post.addCommentOnclick'>
<data:postCommentMsg/></a>
</b:if>
</b:if>

source

Minimalist XSLT Transform Using Two Strings

public string TransformXML(string xml, string xslt)
{
string output = string.Empty;

XPathDocument xpd = new XPathDocument(new StringReader(xml));

XslCompiledTransform transform = new XslCompiledTransform(true);
transform.Load(new XmlTextReader(xslt, XmlNodeType.Document, null));

StringWriter sr = new StringWriter();
transform.Transform(xpd.CreateNavigator(), null, sr);
output = sr.ToString();

return output;
}

//Note that the XSL needs namespace prefixes to make .Net happy:

xsl = @"<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method='text'/>
<xsl:template match='msg'>Found it!</xsl:template>
</xsl:stylesheet>";

xml = @"<msg/>";

source

XMLResourceBundle.class.php – XML Resource Bundle

<?php

/**
 * 
 * @author pizar
 * @copyright Copyright &copy; 2008, pizar
 * 
 * version 1.0
 * Required PHP 5.0
 * 
 * The class is build to read from the xml structure define from the sun.
 * 
 * <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
 * <?xml version="1.0" encoding="iso-8859-1"?>
 * <properties> 
 *     ...
 *     <entry key="invio"><![CDATA[invio]]></entry>
 *     ...
 * </properties>
 *  
 */
class XMLResourceBoundle{

    /**
     * A private variable, who maintain the reference on the xml file
     * @access private
     * @var string
     */
    private $doc="";
    
    
    
    /**
     * Constructor sets up the source file xml to read, and the language from where read.
     * The structure bust be: ${path}/${language}/{$filename}
     * @param string $path
     * @param string $filename
     * @param string $languageCode, the default is ""
     */
    function XMLResourceBoundle(string $path,string $filename, string $languageCode=""){
        $complete_path="";
        
        $this->doc = new DomDocument;
        $this->doc->preserveWhiteSpace = false;
        
        if ($languageCode!=""){
            $complete_path=$path."/".$languageCode."/".$filename;
        }else{
            $complete_path=$path."/".$filename;
        }
        
        $this->doc->load($complete_path);
        $this->xpath = new DOMXPath($this->doc);
    }
    
    /**
     * Constructor sets up the source file xml to read, and the language from where read.
     * The structure bust be: ${path}/${language}/{$filename}
     * @param string the id of the key to get
     * @return string the value of the key in the xml node, if the key is not found, 
     * return the key with ??? before and after. 
     */
    function get(string $keyId){
        $query = "//entry[@key='".$keyId."']";
        $entries = $this->xpath->evaluate($query, $this->doc);
        
        if ($entries->item(0)->nodeValue!=""){
            return($entries->item(0)->nodeValue);
        }else{
            return("???".$keyId."???");
        }
    }
}
?>

source

XML Loader

import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.HTTPStatusEvent;
import flash.events.IEventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;

var dataXML:XML;
var path = "test.xml";
var xmlRequest:URLRequest = new URLRequest(path);
var xmlLoader:URLLoader = new URLLoader()
xmlLoader.dataFormat = URLLoaderDataFormat.TEXT;
configXmlLoaderListeners(xmlLoader);
xmlLoader.load(xmlRequest);

//---------------------------------
//
// Listeners
//
//--------------------------------

function configXmlLoaderListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, xmlCompleteHandler);
dispatcher.addEventListener(Event.OPEN, xmlOpenHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, xmlProgressHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, xmlSecurityErrorHandler);
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, xmlHttpStatusHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, xmlIoErrorHandler);
}

function xmlCompleteHandler(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
//trace("completeHandler: " + loader.data);

try{
dataXML = new XML(event.target.data)
//trace("dataXML " + dataXML);

gotoAndStop("build menu");

} catch (error:TypeError){
trace("Could not parse the XML")
trace(error.message)
}
}

// Optional listeners

function xmlOpenHandler(event:Event):void {
trace("openHandler: " + event);
}

function xmlProgressHandler(event:ProgressEvent):void {
trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
}

function xmlSecurityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}

function xmlHttpStatusHandler(event:HTTPStatusEvent):void {
trace("httpStatusHandler: " + event);
}

function xmlIoErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}

source

Pure Lua XML Parser

function parseargs(s)
local arg = {}
string.gsub(s, "(%w+)=(["'])(.-)%2", function (w, _, a)
arg[w] = a
end)
return arg
end

function collect(s)
local stack = {}
local top = {}
table.insert(stack, top)
local ni,c,label,xarg, empty
local i, j = 1, 1
while true do
ni,j,c,label,xarg, empty = string.find(s, "<(%/?)(%w+)(.-)(%/?)>", i)
if not ni then break end
local text = string.sub(s, i, ni-1)
if not string.find(text, "^%s*$") then
table.insert(top, text)
end
if empty == "/" then  -- empty element tag
table.insert(top, {label=label, xarg=parseargs(xarg), empty=1})
elseif c == "" then   -- start tag
top = {label=label, xarg=parseargs(xarg)}
table.insert(stack, top)   -- new level
else  -- end tag
local toclose = table.remove(stack)  -- remove top
top = stack[#stack]
if #stack < 1 then
error("nothing to close with "..label)
end
if toclose.label ~= label then
error("trying to close "..toclose.label.." with "..label)
end
table.insert(top, toclose)
end
i = j+1
end
local text = string.sub(s, i)
if not string.find(text, "^%s*$") then
table.insert(stack[#stack], text)
end
if #stack > 1 then
error("unclosed "..stack[stack.n].label)
end
return stack[1]
end

source

Create XML from Template and Properties

import groovy.text.XmlTemplateEngine
import java.util.Properties
import java.io.File
import java.io.FileWriter

//Takes a java props file, an XML template file and creates the given output file
void createFile(propertiesFile, templateFileName, outputFileName) {
// read properties file given
def props = new Properties()
props.load(new FileInputStream(new File(propertiesFile)))

// map to the bindings
def bindings = [:]
props.propertyNames().each{prop->
bindings[prop]=props.getProperty(prop)
}

// create the template and make the output file
def engine = new XmlTemplateEngine()
def templateFile = new File(templateFileName)
def output = engine.createTemplate(templateFile).make(bindings)

def outputFile = new File(outputFileName)
def parentFile = outputFile.getParentFile()
if (parentFile != null)	parentFile.mkdirs()
def fileWriter = new FileWriter(outputFile)
fileWriter.write(output.toString())
fileWriter.close()
}

source

// init TextArea component
blurb.html = true;
blurb.wordWrap = true;
blurb.multiline = true;
blurb.label.condenseWhite=true;

// load CSS
madrastyle = new TextField.StyleSheet();
madrastyle.load("madra.css");
blurb.styleSheet = madrastyle;

// load in XML
XMLcontent = new XML();
XMLcontent.ignoreWhite = true;
XMLcontent.load("kungfu.xml");
XMLcontent.onLoad = function(success)
{
if(success)
{
blurb.text = XMLcontent;
}
}

source

parse an xml file with hpricot and Ruby

doc = open("file.xml") { |f| Hpricot.XML(f) }

# examples assuming RSS from a Yahoo! Pipe

items = doc.search "ul.htmlresults > li"

links = items.search "a"

images = items.search "img"

source