Representing a graph in XML
Hi what will the best possible way to represent a graph in XML, where a node can be the child of a parent node and may be the parent of another child node. It can refer to itself, and multiple nodes can have same parent. And a node can have multiple parents. All nodes are from same class. I want to build it efficiently, so that if I can learn about a child node from a parent node I can go to the specific child tag without having to iterate all the nodes. Is it possible? for example here is an overview,
it may look like
<Node name=A> <childNode name=B> <childNode name=C> <childNode name=D> </Node> <Node name=B> <childNode name=C> <childNode name=D> </Node>
So are there any better approaches than this? Whenever I get a child from A i.e. B, than I will have to basically iterate through all Nodes and match there name attribute with B to find the Node that represents B. Can I somehow do it faster?
Since you have a graph, and not a tree as you first thought, why not use GraphML?
GraphML is a comprehensive and easy-to-use file format for graphs. It consists of a language core to describe the structural properties of a graph and a flexible extension mechanism to add application-specific data.
Unlike many other file formats for graphs, GraphML does not use a custom syntax. Instead, it is based on XML and hence ideally suited as a common denominator for all kinds of services generating, archiving, or processing graphs.
GraphXML, GraphXML is a graph description language in XML that can be used œ Data (<data> tag): domain-dependent data represented by a node, edge, or even. In the graph above, Node numbered 0 is the root node – Corresponds to the <breakfast_menu> tag. Node numbered 1 is the immediate child of the root – Corresponds to the <food> tag. Nodes numbered from 2-4 are the tags which come under <food> tag, viz <name>, <price>, <description> and <calories>.
Well, I can't say I fully understand your problem, but I think you're trying to rebuild a (directed) graph in a high level language from an XML file, right? It'd help to know what kind of representation you have in the high level language. Or the language, actually. Assuming C++, and an adjacency list:
I'd first create a
map<string, Node*>, mapping the names to the nodes. My XML would look like this:
<edge from='A' to='B' /> <edge from='A' to='C' /> <edge from='A' to='D' /> <edge from='B' to='C' /> <edge from='B' to='D' />
This is rather compact, and I can parse it with a SAX parser, which is always nice. As I read the edges sequentially, I check to see if I have the nodes in my map already: if not, I store them:
if(mapping.find(from) == map.end()) map.insert(make_pair(from, new Node())); if(mapping.find(to) == map.end()) map.insert(make_pair(to, new Node()));
Once both end nodes are in the map, we can add the edge by:
Once the parsing is complete, you have the nodes in the map, nicely ordered by name.
Anyhow, you may want to look at Wikipedia's summary about graph representations, that may give you ideas.
RDF Research notebook: On edge-labelled graphs in XML, The elements and attributes in an XML document often are a representation of objects from a specific data model such as Directed-Labelled-Graph or Database this is an example xml file that I want to represent : the graph will be like this: brad pitt will be represented in a rectangle and this rectangle will be connected with ellipses that represent the data as actor, producer what you tried please paste your on the basis that we will help you.
Take a look at RDF/XML.
RDF is a simple data model for the semantic web (linked-data) consisting of triples (Subject, Predicate, Object). It can represent graphs and is serializable in a number of formats including xml, json (json-ld) and turtle.
An XML based graph interchange format, However, in applications, graphs usually represent domain-specific data along with its semantics, which must also be represented in the interchange format. 2.2 The arcs of the graph (the arrows) represent relationships between the nodes. An XML document is a tree, which is a particular sort of directed graph. If we add to XML a way of making arcs which link XML arbitrary elements then it can be a more general DLG.
XML graphs in program analysis, elements correspond to labeled nodes with children representing the element contents. XML graphs generalize the notion of XML trees in a number of directions The edge direction is determined by graph.directed property if not present. A metadata property allows for custom data on an object. Its values is defined as a JSON object. graph object. A graph object represents a single conceptual graph. graph properties. An optional id property provides an identifier for this graph object
Graph representation, in the XML-QL data model, of the XML , Download scientific diagram | Graph representation, in the XML-QL data model, of the XML document presented in Table 1. from publication: Querying XML Read and learn for free about the following article: Representing graphs If you're seeing this message, it means we're having trouble loading external resources on our website. If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.
Visualizing XML as a Graph Using Neo4j, An easy representation can be done in GraphGist. I have created the graph of this xml. Here is the link to the gist. Also, the gist script can be found Adjacency Matrix is a 2D array of size V x V where V is the number of vertices in a graph. Let the 2D array be adj, a slot adj[i][j] = 1 indicates that there is an edge from vertex i to vertex j. Adjacency matrix for undirected graph is always symmetric. Adjacency Matrix is also used to represent weighted graphs.