Hello Bergos
With a RDF/XML content that contains ref:ParseType="Literal" , Can you suggest the right technique for parsing RDF/XML that contains ref:ParseType="Literal"?
With my test data as posted on this message, I try to parse it by accessing "Gain" value with data.object.nominalValue.lastChild.nodeValue Is it the right technique with your library design?
I cannot find supported documentation on this issue. If you have suggestion , please advise. I posted complete of code, test data, and console output as follow.
Thank you ,
Vorachet Jaroensawas
// My code
theRdfXmlParser.parse(sample_simulinkblocks_in_rdf, function(graph) {
graph.forEach(function(data){
console.log('------------- graph.forEach -----------');
console.log('subject toString(): ' + data.subject.toString());
console.log('predicate toString(): ' + data.predicate.toString());
console.log('object toString(): ' + data.object.toString());
console.log('subject nominalValue: ' + data.subject.nominalValue);
console.log('predicate nominalValue: ' + data.predicate.nominalValue);
console.log('object nominalValue: ' + data.object.nominalValue);
if (typeof data.object.nominalValue == 'string' || data.object.nominalValue instanceof String) {
// Do nothing
console.log('data.object.nominalValue is string"');
}else{
console.log('Detected rdf:parseType="Literal"');
console.log(data.object.nominalValue); // <--- It will print array in console
// I try to access "Gain" value with data.object.nominalValue.lastChild.nodeValue
}
});
});
// Test RDF/XML Data
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:simulink_block="http://mathworks.com/simulink/rdf#Block/"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" >
<rdf:Description rdf:about="http://localhost/test/Subsystem:Gain">
<rdf:type rdf:resource="http://mathworks.com/simulink/rdf#Block"/>
<simulink_block:parameter rdf:resource="http://localhost/test//Subsystem1::Gain::RndMeth"/>
<simulink_block:name rdf:parseType="Literal">Gain</simulink_block:name>
<simulink_block:type rdf:parseType="Literal">Gain</simulink_block:type>
</rdf:Description>
</rdf:RDF>
// Some console output as captured in graph.forEach() loop.
------------- graph.forEach -----------
subject toString(): http://localhost/test/Subsystem:Gain
predicate toString(): http://www.w3.org/1999/02/22-rdf-syntax-ns#type
object toString(): http://mathworks.com/simulink/rdf#Block
subject nominalValue: http://localhost/test/Subsystem:Gain
predicate nominalValue: http://www.w3.org/1999/02/22-rdf-syntax-ns#type
object nominalValue: http://mathworks.com/simulink/rdf#Block
data.object.nominalValue is string"
------------- graph.forEach -----------
subject toString(): http://localhost/test/Subsystem:Gain
predicate toString(): http://mathworks.com/simulink/rdf#Block/parameter
object toString(): http://localhost/test//Subsystem1::Gain::RndMeth
subject nominalValue: http://localhost/test/Subsystem:Gain
predicate nominalValue: http://mathworks.com/simulink/rdf#Block/parameter
object nominalValue: http://localhost/test//Subsystem1::Gain::RndMeth
data.object.nominalValue is string"
------------- graph.forEach -----------
subject toString(): http://localhost/test/Subsystem:Gain
predicate toString(): http://mathworks.com/simulink/rdf#Block/name
object toString(): <simulink_block:name>Gain</simulink_block:name>
subject nominalValue: http://localhost/test/Subsystem:Gain
predicate nominalValue: http://mathworks.com/simulink/rdf#Block/name
object nominalValue: <simulink_block:name>Gain</simulink_block:name>
Detected rdf:parseType="Literal"
{ _nsMap: {},
attributes:
{ '0':
{ ownerDocument: [Object],
nodeName: 'rdf:parseType',
name: 'rdf:parseType',
namespaceURI: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
specified: true,
prefix: 'rdf',
localName: 'parseType',
nodeValue: 'Literal',
value: 'Literal',
ownerElement: null },
_ownerElement: [Circular],
length: 0 },
childNodes:
{ '0':
{ ownerDocument: [Object],
data: 'Gain',
nodeValue: 'Gain',
length: 4,
parentNode: [Circular],
previousSibling: null,
nextSibling: null,
lineNumber: 6,
columnNumber: 54 },
length: 1 },
ownerDocument:
{ doctype: null,
implementation: { _features: {} },
childNodes: { '0': [Object], '1': [Object], length: 2 },
documentURI: undefined,
firstChild:
{ ownerDocument: [Circular],
target: 'xml',
tagName: 'xml',
data: 'version="1.0" encoding="UTF-8"',
nodeValue: 'version="1.0" encoding="UTF-8"',
lineNumber: 1,
columnNumber: 1,
previousSibling: null,
nextSibling: [Object],
parentNode: [Circular] },
lastChild:
{ _nsMap: {},
attributes: [Object],
childNodes: [Object],
ownerDocument: [Circular],
nodeName: 'rdf:RDF',
tagName: 'rdf:RDF',
namespaceURI: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
prefix: 'rdf',
localName: 'RDF',
previousSibling: [Object],
nextSibling: null,
parentNode: [Circular],
lineNumber: 2,
columnNumber: 1,
firstChild: [Object],
lastChild: [Object] },
_inc: 37,
documentElement:
{ _nsMap: {},
attributes: [Object],
childNodes: [Object],
ownerDocument: [Circular],
nodeName: 'rdf:RDF',
tagName: 'rdf:RDF',
namespaceURI: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
prefix: 'rdf',
localName: 'RDF',
previousSibling: [Object],
nextSibling: null,
parentNode: [Circular],
lineNumber: 2,
columnNumber: 1,
firstChild: [Object],
lastChild: [Object] } },
nodeName: 'simulink_block:name',
tagName: 'simulink_block:name',
namespaceURI: 'http://mathworks.com/simulink/rdf#Block/',
prefix: 'simulink_block',
localName: 'name',
parentNode:
{ _nsMap: {},
attributes: { '0': [Object], _ownerElement: [Circular], length: 0 },
childNodes:
{ '0': [Object],
'1': [Object],
'2': [Object],
'3': [Object],
'4': [Object],
'5': [Circular],
'6': [Object],
'7': [Object],
'8': [Object],
length: 9 },
ownerDocument:
{ doctype: null,
implementation: [Object],
childNodes: [Object],
documentURI: undefined,
firstChild: [Object],
lastChild: [Object],
_inc: 37,
documentElement: [Object] },
nodeName: 'rdf:Description',
tagName: 'rdf:Description',
namespaceURI: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
prefix: 'rdf',
localName: 'Description',
parentNode:
{ _nsMap: {},
attributes: [Object],
childNodes: [Object],
ownerDocument: [Object],
nodeName: 'rdf:RDF',
tagName: 'rdf:RDF',
namespaceURI: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
prefix: 'rdf',
localName: 'RDF',
previousSibling: [Object],
nextSibling: null,
parentNode: [Object],
lineNumber: 2,
columnNumber: 1,
firstChild: [Object],
lastChild: [Object] },
previousSibling:
{ ownerDocument: [Object],
data: '\n\n ',
nodeValue: '\n\n ',
length: 6,
parentNode: [Object],
previousSibling: null,
nextSibling: [Circular],
lineNumber: 2,
columnNumber: 57 },
nextSibling:
{ ownerDocument: [Object],
data: '\n\n',
nodeValue: '\n\n',
length: 2,
parentNode: [Object],
previousSibling: [Circular],
nextSibling: null,
lineNumber: 8,
columnNumber: 23 },
lineNumber: 3,
columnNumber: 5,
firstChild:
{ ownerDocument: [Object],
data: ' \n ',
nodeValue: ' \n ',
length: 17,
parentNode: [Circular],
previousSibling: null,
nextSibling: [Object],
lineNumber: 3,
columnNumber: 71 },
lastChild:
{ ownerDocument: [Object],
data: '\n ',
nodeValue: '\n ',
length: 5,
parentNode: [Circular],
previousSibling: [Object],
nextSibling: null,
lineNumber: 7,
columnNumber: 80 } },
previousSibling:
{ ownerDocument:
{ doctype: null,
implementation: [Object],
childNodes: [Object],
documentURI: undefined,
firstChild: [Object],
lastChild: [Object],
_inc: 37,
documentElement: [Object] },
data: '\n ',
nodeValue: '\n ',
length: 9,
parentNode:
{ _nsMap: {},
attributes: [Object],
childNodes: [Object],
ownerDocument: [Object],
nodeName: 'rdf:Description',
tagName: 'rdf:Description',
namespaceURI: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
prefix: 'rdf',
localName: 'Description',
parentNode: [Object],
previousSibling: [Object],
nextSibling: [Object],
lineNumber: 3,
columnNumber: 5,
firstChild: [Object],
lastChild: [Object] },
previousSibling:
{ _nsMap: {},
attributes: [Object],
childNodes: {},
ownerDocument: [Object],
nodeName: 'simulink_block:parameter',
tagName: 'simulink_block:parameter',
namespaceURI: 'http://mathworks.com/simulink/rdf#Block/',
prefix: 'simulink_block',
localName: 'parameter',
parentNode: [Object],
previousSibling: [Object],
nextSibling: [Circular],
lineNumber: 5,
columnNumber: 9 },
nextSibling: [Circular],
lineNumber: 5,
columnNumber: 100 },
nextSibling:
{ ownerDocument:
{ doctype: null,
implementation: [Object],
childNodes: [Object],
documentURI: undefined,
firstChild: [Object],
lastChild: [Object],
_inc: 37,
documentElement: [Object] },
data: '\n ',
nodeValue: '\n ',
length: 9,
parentNode:
{ _nsMap: {},
attributes: [Object],
childNodes: [Object],
ownerDocument: [Object],
nodeName: 'rdf:Description',
tagName: 'rdf:Description',
namespaceURI: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
prefix: 'rdf',
localName: 'Description',
parentNode: [Object],
previousSibling: [Object],
nextSibling: [Object],
lineNumber: 3,
columnNumber: 5,
firstChild: [Object],
lastChild: [Object] },
previousSibling: [Circular],
nextSibling:
{ _nsMap: {},
attributes: [Object],
childNodes: [Object],
ownerDocument: [Object],
nodeName: 'simulink_block:type',
tagName: 'simulink_block:type',
namespaceURI: 'http://mathworks.com/simulink/rdf#Block/',
prefix: 'simulink_block',
localName: 'type',
parentNode: [Object],
previousSibling: [Circular],
nextSibling: [Object],
lineNumber: 7,
columnNumber: 9,
firstChild: [Object],
lastChild: [Object] },
lineNumber: 6,
columnNumber: 80 },
lineNumber: 6,
columnNumber: 9,
firstChild:
{ ownerDocument:
{ doctype: null,
implementation: [Object],
childNodes: [Object],
documentURI: undefined,
firstChild: [Object],
lastChild: [Object],
_inc: 37,
documentElement: [Object] },
data: 'Gain',
nodeValue: 'Gain',
length: 4,
parentNode: [Circular],
previousSibling: null,
nextSibling: null,
lineNumber: 6,
columnNumber: 54 },
lastChild:
{ ownerDocument:
{ doctype: null,
implementation: [Object],
childNodes: [Object],
documentURI: undefined,
firstChild: [Object],
lastChild: [Object],
_inc: 37,
documentElement: [Object] },
data: 'Gain',
nodeValue: 'Gain',
length: 4,
parentNode: [Circular],
previousSibling: null,
nextSibling: null,
lineNumber: 6,
columnNumber: 54 } }
------------- graph.forEach -----------
subject toString(): http://localhost/test/Subsystem:Gain
predicate toString(): http://mathworks.com/simulink/rdf#Block/type
object toString(): <simulink_block:type>Gain</simulink_block:type>
subject nominalValue: http://localhost/test/Subsystem:Gain
predicate nominalValue: http://mathworks.com/simulink/rdf#Block/type
object nominalValue: <simulink_block:type>Gain</simulink_block:type>
Detected rdf:parseType="Literal"
{ _nsMap: {},
attributes:
{ '0':
{ ownerDocument: [Object],
nodeName: 'rdf:parseType',
name: 'rdf:parseType',
namespaceURI: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
specified: true,
prefix: 'rdf',
localName: 'parseType',
nodeValue: 'Literal',
value: 'Literal',
ownerElement: null },
_ownerElement: [Circular],
length: 0 },
childNodes:
{ '0':
{ ownerDocument: [Object],
data: 'Gain',
nodeValue: 'Gain',
length: 4,
parentNode: [Circular],
previousSibling: null,
nextSibling: null,
lineNumber: 7,
columnNumber: 54 },
length: 1 },
ownerDocument:
{ doctype: null,
implementation: { _features: {} },
childNodes: { '0': [Object], '1': [Object], length: 2 },
documentURI: undefined,
firstChild:
{ ownerDocument: [Circular],
target: 'xml',
tagName: 'xml',
data: 'version="1.0" encoding="UTF-8"',
nodeValue: 'version="1.0" encoding="UTF-8"',
lineNumber: 1,
columnNumber: 1,
previousSibling: null,
nextSibling: [Object],
parentNode: [Circular] },
lastChild:
{ _nsMap: {},
attributes: [Object],
childNodes: [Object],
ownerDocument: [Circular],
nodeName: 'rdf:RDF',
tagName: 'rdf:RDF',
namespaceURI: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
prefix: 'rdf',
localName: 'RDF',
previousSibling: [Object],
nextSibling: null,
parentNode: [Circular],
lineNumber: 2,
columnNumber: 1,
firstChild: [Object],
lastChild: [Object] },
_inc: 37,
documentElement:
{ _nsMap: {},
attributes: [Object],
childNodes: [Object],
ownerDocument: [Circular],
nodeName: 'rdf:RDF',
tagName: 'rdf:RDF',
namespaceURI: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
prefix: 'rdf',
localName: 'RDF',
previousSibling: [Object],
nextSibling: null,
parentNode: [Circular],
lineNumber: 2,
columnNumber: 1,
firstChild: [Object],
lastChild: [Object] } },
nodeName: 'simulink_block:type',
tagName: 'simulink_block:type',
namespaceURI: 'http://mathworks.com/simulink/rdf#Block/',
prefix: 'simulink_block',
localName: 'type',
parentNode:
{ _nsMap: {},
attributes: { '0': [Object], _ownerElement: [Circular], length: 0 },
childNodes:
{ '0': [Object],
'1': [Object],
'2': [Object],
'3': [Object],
'4': [Object],
'5': [Object],
'6': [Object],
'7': [Circular],
'8': [Object],
length: 9 },
ownerDocument:
{ doctype: null,
implementation: [Object],
childNodes: [Object],
documentURI: undefined,
firstChild: [Object],
lastChild: [Object],
_inc: 37,
documentElement: [Object] },
nodeName: 'rdf:Description',
tagName: 'rdf:Description',
namespaceURI: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
prefix: 'rdf',
localName: 'Description',
parentNode:
{ _nsMap: {},
attributes: [Object],
childNodes: [Object],
ownerDocument: [Object],
nodeName: 'rdf:RDF',
tagName: 'rdf:RDF',
namespaceURI: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
prefix: 'rdf',
localName: 'RDF',
previousSibling: [Object],
nextSibling: null,
parentNode: [Object],
lineNumber: 2,
columnNumber: 1,
firstChild: [Object],
lastChild: [Object] },
previousSibling:
{ ownerDocument: [Object],
data: '\n\n ',
nodeValue: '\n\n ',
length: 6,
parentNode: [Object],
previousSibling: null,
nextSibling: [Circular],
lineNumber: 2,
columnNumber: 57 },
nextSibling:
{ ownerDocument: [Object],
data: '\n\n',
nodeValue: '\n\n',
length: 2,
parentNode: [Object],
previousSibling: [Circular],
nextSibling: null,
lineNumber: 8,
columnNumber: 23 },
lineNumber: 3,
columnNumber: 5,
firstChild:
{ ownerDocument: [Object],
data: ' \n ',
nodeValue: ' \n ',
length: 17,
parentNode: [Circular],
previousSibling: null,
nextSibling: [Object],
lineNumber: 3,
columnNumber: 71 },
lastChild:
{ ownerDocument: [Object],
data: '\n ',
nodeValue: '\n ',
length: 5,
parentNode: [Circular],
previousSibling: [Circular],
nextSibling: null,
lineNumber: 7,
columnNumber: 80 } },
previousSibling:
{ ownerDocument:
{ doctype: null,
implementation: [Object],
childNodes: [Object],
documentURI: undefined,
firstChild: [Object],
lastChild: [Object],
_inc: 37,
documentElement: [Object] },
data: '\n ',
nodeValue: '\n ',
length: 9,
parentNode:
{ _nsMap: {},
attributes: [Object],
childNodes: [Object],
ownerDocument: [Object],
nodeName: 'rdf:Description',
tagName: 'rdf:Description',
namespaceURI: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
prefix: 'rdf',
localName: 'Description',
parentNode: [Object],
previousSibling: [Object],
nextSibling: [Object],
lineNumber: 3,
columnNumber: 5,
firstChild: [Object],
lastChild: [Object] },
previousSibling:
{ _nsMap: {},
attributes: [Object],
childNodes: [Object],
ownerDocument: [Object],
nodeName: 'simulink_block:name',
tagName: 'simulink_block:name',
namespaceURI: 'http://mathworks.com/simulink/rdf#Block/',
prefix: 'simulink_block',
localName: 'name',
parentNode: [Object],
previousSibling: [Object],
nextSibling: [Circular],
lineNumber: 6,
columnNumber: 9,
firstChild: [Object],
lastChild: [Object] },
nextSibling: [Circular],
lineNumber: 6,
columnNumber: 80 },
nextSibling:
{ ownerDocument:
{ doctype: null,
implementation: [Object],
childNodes: [Object],
documentURI: undefined,
firstChild: [Object],
lastChild: [Object],
_inc: 37,
documentElement: [Object] },
data: '\n ',
nodeValue: '\n ',
length: 5,
parentNode:
{ _nsMap: {},
attributes: [Object],
childNodes: [Object],
ownerDocument: [Object],
nodeName: 'rdf:Description',
tagName: 'rdf:Description',
namespaceURI: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
prefix: 'rdf',
localName: 'Description',
parentNode: [Object],
previousSibling: [Object],
nextSibling: [Object],
lineNumber: 3,
columnNumber: 5,
firstChild: [Object],
lastChild: [Circular] },
previousSibling: [Circular],
nextSibling: null,
lineNumber: 7,
columnNumber: 80 },
lineNumber: 7,
columnNumber: 9,
firstChild:
{ ownerDocument:
{ doctype: null,
implementation: [Object],
childNodes: [Object],
documentURI: undefined,
firstChild: [Object],
lastChild: [Object],
_inc: 37,
documentElement: [Object] },
data: 'Gain',
nodeValue: 'Gain',
length: 4,
parentNode: [Circular],
previousSibling: null,
nextSibling: null,
lineNumber: 7,
columnNumber: 54 },
lastChild:
{ ownerDocument:
{ doctype: null,
implementation: [Object],
childNodes: [Object],
documentURI: undefined,
firstChild: [Object],
lastChild: [Object],
_inc: 37,
documentElement: [Object] },
data: 'Gain',
nodeValue: 'Gain',
length: 4,
parentNode: [Circular],
previousSibling: null,
nextSibling: null,
lineNumber: 7,
columnNumber: 54 } }