Skip to content

Instantly share code, notes, and snippets.

@kenwebb
Last active October 9, 2018 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenwebb/be1e526e785422fe2af03fe08a75f71c to your computer and use it in GitHub Desktop.
Save kenwebb/be1e526e785422fe2af03fe08a75f71c to your computer and use it in GitHub Desktop.
Processing Instruction and XML Parsing
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Tue Oct 09 2018 08:41:22 GMT-0400 (Eastern Daylight Time)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: Processing Instruction and XML Parsing
Description:
Url: http://www.primordion.com/Xholon/gwt/
InternalName: be1e526e785422fe2af03fe08a75f71c
Keywords:
My Notes
--------
October 8, 2018
see my written notes for October 3 2018, where I consider multiple ways to partition a Xholon app so parts can run in different address spaces
I have added some code to:
org.primordion.xholon.io.xml.XmlGwtDomReader
org.primordion.xholon.io.xml.Xml2Xholon
example of an XML Processing Instruction (PI):
<?xml version="1.0" encoding="UTF-8"?>
<?Testing 123 456 789 ?>
<Hello/>
Example of two versions "ver":
http://127.0.0.1:8888/Xholon.html?app=Processing+Instruction+and+XML+Parsing&src=lstr&gui=clsc&ver=Hello
http://127.0.0.1:8888/Xholon.html?app=Processing+Instruction+and+XML+Parsing&src=lstr&gui=clsc&ver=World
http://127.0.0.1:8888/Xholon.html?app=be1e526e785422fe2af03fe08a75f71c&src=gist&gui=clsc&ver=Hello
http://127.0.0.1:8888/Xholon.html?app=be1e526e785422fe2af03fe08a75f71c&src=gist&gui=clsc&ver=World
http://127.0.0.1:8888/XholonWebRTC.html?app=be1e526e785422fe2af03fe08a75f71c&src=gist&gui=clsc&ver=Hello
http://127.0.0.1:8888/XholonWebRTC.html?app=be1e526e785422fe2af03fe08a75f71c&src=gist&gui=clsc&ver=World
example of xmlreader PI data; an array of versions, each with its own list of patches:
[
{"ver":"Hello", "patches":
[
{"op":"add", "sel":".", "pos":"append", "content":"<One><Two/></One>"},
{"op":"add", "sel":"./Zero", "pos":"append", "content":"<Three><Four/></Three>"}
]
},
{"ver":"World", "patches":
[
{"op":"add", "sel":".", "pos":"append", "content":"<One><Two/></One>"},
{"op":"replace", "sel":"./Zero", "content":"<Three><Four/></Three>"},
{"op":"remove", "sel":"./Ten"}
]
}
]
References
----------
(1) https://en.wikipedia.org/wiki/Processing_Instruction
A Processing Instruction (PI) is an SGML and XML node type, which may occur anywhere in the document, intended to carry instructions to the application.
Processing instructions are exposed in the Document Object Model as Node.PROCESSING_INSTRUCTION_NODE,
and they can be used in XPath and XQuery with the 'processing-instruction()' command.
An XML processing instruction is enclosed within <? and ?>, and contains a target and optionally some content, which is the node value, that cannot contain the sequence ?>.
<?PITarget PIContent?>
The most common use of a processing instruction is to request the XML document be rendered using a stylesheet using the 'xml-stylesheet' target, which was standardized in 1999.
It can be used for both XSLT and CSS stylesheets.
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<?xml-stylesheet type="text/css" href="style.css"?>
(2) http://www.w3.org/TR/REC-xml/#sec-pi
(3) Elliotte Rusty Harold, W. Scott Means. XML in a nutshell. p. 23. ISBN 978-0-596-00764-5.
KSW I have this book
(4) http://www.sagehill.net/docbookxsl/ProcessingInstructions.html
(5) https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
]]></Notes>
<_-.XholonClass>
<!-- domain objects -->
<PhysicalSystem/>
<Block/>
<Brick/>
<PlaceHolder/>
<!-- quantities -->
<Height superClass="Quantity"/>
<Width superClass="Quantity"/>
</_-.XholonClass>
<xholonClassDetails>
<Block>
<?xmlreader-patch
{
"Hello":
[
{"op":"replace", "sel":"./port/@name", "pos":"append", "content":"hite"}
]
}
?>
<port name="height" connector="Height"/>
</Block>
</xholonClassDetails>
<PhysicalSystem>
<!-- TODO I may want to allow only one PI per Xholon node; below there are three -->
<?TestingPI This is some text content for testing PI.
Xml2Xholon should log this to the Dev Tools console.
?>
<?PIZero zero?>
<!--<?xmlreader This is directed to an XmlReader such as XmlGwtDomReader.?>-->
<!--<?xmlreader <add sel="."><One><Two/></One></add>?>-->
<!--<?xmlreader {"op":"add", "sel":"descendant::IslandSystem/Space/FieldRow[55]/LandCell[18]"," pos":"append", "content":"<Stick/>"}?>-->
<!-- the following has the same JSON fornmat that I use in MeteorPlatformService.java; and I've also added an optional version ID "ver" -->
<!--<?xmlreader [{"op":"add", "sel":".", "pos":"append", "content":"<One><Two/></One>", "ver":"Hello"}, {"op":"add", "sel":".", "pos":"append", "content":"<Three><Four/></Three>", "ver":"World"}]?>-->
<?xmlreader-patch
{
"Hello":
[
{"op":"add", "sel":".", "pos":"append", "content":"<One><Two/></One>"},
{"op":"add", "sel":"./Brick", "pos":"append", "content":"<Three><Four/></Three>"}
],
"World": [
{"op":"add", "sel":".", "pos":"append", "content":"<One><Two/></One>"},
{"op":"remove", "sel":"./Block/Height"},
{"op":"replace", "sel":"./PlaceHolder", "content":"<Block roleName=\"Cube\"><Height>0.234 m</Height></Block>"}
]
}
?>
<Block>
<?PIOne one ?>
<Height>0.1 m<?PITwo two ?></Height>
<!--<?PIThree three ?> ONLY LOCATE A PI NODE AS THE FIRST CHILD OF AN ELEMENT NODE -->
<Width>0.25 m</Width>
</Block>
<!--<?PIFour four ?> ONLY LOCATE A PI NODE AS THE FIRST CHILD OF AN ELEMENT NODE -->
<Brick multiplicity="2"/>
<PlaceHolder/>
<!--<?PIFive five ?> ONLY LOCATE A PI NODE AS THE FIRST CHILD OF AN ELEMENT NODE -->
</PhysicalSystem>
<Blockbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var a = 123;
var b = 456;
var c = a * b;
if (console) {
console.log(c);
}
//# sourceURL=Blockbehavior.js
]]></Blockbehavior>
<Heightbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var myHeight, testing;
var beh = {
postConfigure: function() {
testing = Math.floor(Math.random() * 10);
myHeight = this.cnode.parent();
},
act: function() {
myHeight.println(this.toString());
},
toString: function() {
return "testing:" + testing;
}
}
//# sourceURL=Heightbehavior.js
]]></Heightbehavior>
<Brickbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
$wnd.xh.Brickbehavior = function Brickbehavior() {}
$wnd.xh.Brickbehavior.prototype.postConfigure = function() {
this.brick = this.cnode.parent();
this.iam = " red brick";
};
$wnd.xh.Brickbehavior.prototype.act = function() {
this.brick.println("I am a" + this.iam);
};
//# sourceURL=Brickbehavior.js
]]></Brickbehavior>
<Brickbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
console.log("I'm another brick behavior");
]]></Brickbehavior>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Block</title>
<rect id="PhysicalSystem/Block" fill="#98FB98" height="50" width="50" x="25" y="0"/>
<g>
<title>Width</title>
<rect id="PhysicalSystem/Block/Width" fill="#6AB06A" height="50" width="10" x="80" y="0"/>
</g>
</g>
</svg>
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient>
</XholonWorkbook>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment