XMLGraph
BeginPackage["XMLGraph`"];
⌈ XMLGraph is an object that is stored as XMLGraph[data] where data is an Association or other object that supports key access mechanisms that stores the core XMLGraph data. Keys *must* include “Graph”, “Data”, “Version”. Data -- data for each node Graph -- structural representation of the XML Version -- version of the object API Each node in Graph will have an entry in Data. Structural lookups happen on the Graph. Data lookups happen on the data.⌋
XMLGraph::usage= "A Graph-based representation of XML data";
BeginPackage["`Package`"];
⌈Node Stuff⌋
$NodeDefaults::usage="Defaults for created nodes";Node::usage="Head for a node";
CreateNode::usage= "Creates a node/set of nodes";InsertNodes::usage= "Adds nodes to the graph";DeleteNodes::usage= "Deletes nodes from the graph";ModifyNodes::usage= "Modifies a node or set of nodes on the graph";
RootNode::usage= "Gets the XML root element";NodeList::usage= "Lists the nodes on the Graph";NodeData::usage= "Gets a set of nodes off the graph";NodeAttributes::usage= "Pulls node attributes off the graph";SelectNodes::usage= "Selects nodes by some criterion";
NodeChildren::usage="";NodeParents::usage="";
⌈Object Stuff⌋
⌈Conversions⌋
⌈Graph Operations⌋
XMLSubgraph::usage="Extracts a subgraph starting from a head node";FormattedXMLGraph::usage="Returns the Graph with nice formatting";XMLGraphSort::usage="Sorts the XMLGraph by distance from the \"Root\" node";
XMLGraphBFS::usage="Applies BreadthFirstScan to the Graph";XMLGraphDFS::usage="Applies DepthFirstScan to the Graph";
EndPackage[];
BeginPackage["`CSSSelectors`"];
EndPackage[];
Begin["`Private`"];
⌈Object API⌋
XMLGraph//Clear
⌈XMLGraphQ⌋
⌈XMLGraphQ⌋
⌈MutableXMLGraphQ⌋
⌈Constructor⌋
⌈XMLGraph⌋
⌈ConstructXMLGraph⌋
⌈MutableXMLGraph⌋
⌈Accessor API⌋
⌈Format⌋
Format[x_XMLGraph?XMLGraphQ]:= RawBoxes@ With g=Length@x["Nodes"]-1, r=Replace[x["Root"],s:Except[None]:>x["Data"][s,"Type"]], be=x["Backend"] , BoxForm`ArrangeSummaryBox XMLGraph, Unevaluated[XMLGraph@@{be}], None, BoxForm`MakeSummaryItem[{"Root: ",r},StandardForm], BoxForm`MakeSummaryItem[{"Nodes: ",g},StandardForm] , {}, StandardForm
⌈Methods/Attributes⌋
⌈Bind⌋
⌈Insert⌋
⌈Delete⌋
⌈Modify⌋
⌈FormattedGraph⌋
⌈Nodes⌋
⌈Root⌋
⌈Select⌋
⌈Locate⌋
⌈BFS⌋
⌈DFS⌋
⌈Data⌋
⌈Type⌋
⌈Meta⌋
⌈Attribute⌋
⌈Parent⌋
⌈FullParents⌋
⌈Children⌋
⌈FullChildren⌋
⌈Sort⌋
⌈Subgraph⌋
⌈XML⌋
⌈Association⌋
⌈Fallthrough⌋
⌈Node API⌋
⌈$NodeDefaults⌋
⌈ValidateNode⌋
⌈Node⌋
⌈CreateNode⌋
⌈ CreateNode takes a parent node and a list of child-specs and creates an Association for the children out of it. Returns {{childData}, {nodeSpecs...}} where each nodeSpec is an Association and the childData is data about the children of the parent node.⌋
⌈CreateNode⌋
⌈createNode⌋
createNode[parent_XMLObject[_][_,el_,___]]:= createNode parent->el createNode[parent_XMLElement[d_,c_,b_]]:= createNode parent-> <|"Type"d,"Meta"c,"Children"b|> ;createNode[parent_kid_Association]:= Module data=<|"Parent"parent|>, children , data["Type"]=Lookup[kid,"Type",$NodeDefaults["Type"]]; data["Name"]=StringSplit[CreateUUID[data["Type"]<>":"],"-",2][[1]]; data["Meta"]=Lookup[kid,"Meta",$NodeDefaults["Meta"]]; data["Children"]= createNode data["Name"]-> Flatten@List@Lookup[kid,"Children",$NodeDefaults["Children"]] ; Sow[data]; Node[data["Name"]] createNode[parent_kids:l_List]:= createNode/@Thread[parentkids];createNode[parent_kid_]:= kid
⌈CSS Selectors⌋
⌈Conversion API⌋
⌈FromXMLAssociation⌋
⌈FromXMLObject⌋