Unable to Parse this RDF/XML since System.Xml was unable to parse the document - namespaces

I'am using .Net RDF library to make some sparql query on RDF files.
but when I tried to load the RDF file to C# .Net RDFlibrary.
The error is:
Unable to Parse this RDF/XML since System.Xml was unable to parse
the document, see Inner Exception for details
My RDF file:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rdf:RDF [<!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'>
<!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'>]>
<rdf:RDF xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dnr="http://www.dotnetrdf.org/configuration#"
xmlns:rdf="http://www.w3.org/XML/1998/namespace#"
xml:base="http://www.example.org/">
<rdf:Description rdf:about="Fadi">
<ns0:eat xmlns:ns0="http://example.org/">Apple</ns0:eat>
<xml:startTime>00:01:38</xml:startTime>
<xml:endTime>00:01:39</xml:endTime>
</rdf:Description>
</rdf:RDF>
and the statement to load:
Graph myGraph = new Graph();
FileLoader.Load(myGraph, "C:\\Users\\hasoOn\\Desktop\\tt.rdf");
Can anyone tell me what is wrong? - and why I get this error?

Did you actually look at the Inner Exception as the exception messages tells you to? That would contain the XmlException that was produced and would tell you exactly what is wrong with your RDF/XML including positional information i.e. where in the file the error is.
In your case your problem happens to be that you have defined the rdf namespace twice on the same element i.e. you have two xmlns:rdf attributes on your root rdf:RDF element which makes your XML illegal.
If you remove that then it will be valid XML however it will still fail to parse in dotNetRDF because you have used the properties xml:startTime and xml:endTime without defining the xml namespace. I guess dotNetRDF should probably allow those because xml: is implicitly defined in XML though using the xml namespace for anything other than XML syntax itself is generally a very bad idea and a symptom of bad data modeling.

Related

WSO2 data service and data mapper

I am trying to apply the data mapper mediator to the output of the XML data service defined within WSO2EI. Documentation indicates, that to use the data mapper you need to have a fully qualified names in the XML input files.
The data service I am creating does not include qualified prefixes within the XML it generates.
I tried to export the XSLT data mapping from the CAR file and run it along the sample XML generated by the data service through the external XML transformer - it did not work. However, if I added qualified prefixes in the input XML manually, everything works fine.
It seems that the reason for my data mapper not working is the default, and not qualified, namespace in the input XML. Unfortunately, I cannot get the data service including namespace prexifes in its output. Any ideas?
To illustrate the nature of the problem let us consider two slightly different inputs; first XML input file uses the default names, second one qualified names:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<users xmlns="http://ws.wso2.org/dataservice">
<user>
<last>Waelchi</last>
<first>Xzavier</first>
<country>Swaziland</country>
</user>
</users>
</soapenv:Body>
</soapenv:Envelope>
This XML is not properly handled by the XSLT, no matter if within WSO2EI, or external XML processor. However, the same XML with qualified names:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<users xmlns:p="http://ws.wso2.org/dataservice">
<p:user>
<p:last>Waelchi</p:last>
<p:first>Xzavier</p:first>
<p:country>Swaziland</p:country>
</p:user>
</users>
</soapenv:Body>
</soapenv:Envelope>
is properly interpreted at least by the external XML processor. My problem is, that I cannot get WSO2EI data service to include qualified prefixes in its output.
OK, I have managed to bypass the problem transforming XML output by WSO2 data service into qualified XML using XSLT transform. However, I am still unable to get qualified XML directly from the data service; any suggestion shall be appreciated.

SchemaLocation in JIBX generated xml

I am generating xml from Java object using JIBX. I want schemalocation to be set in generated xml. I am able to put namespace but but schemaLocation. Anyone has one idea how to do it?
You should be able to do this as an attribute value on the root element of your output document, along these lines:
<value name="schemaLocation" ns="http://www.w3.org/2001/XMLSchema" field="locationField"/>

Parsing phpdoc to JSON

I would like to find a way to use phpdoc2 to parse PHP projects into JSON rather than into Abstract Syntax Tree XML. Although of course I could just parse the XML into JSON, it seems that creating XML would be unnecessary overhead here.
So, in a nut shell, the question is: is there an easy way to configure phpdoc2's parser to directly produce JSON instead of XML? Or maybe some clues on what to extend in phpdoc2 to route the parsing output into JSON?
The story behind this question is: I would like to create JSDuck-like documentation for my PHP project. Although I have found that JSDuck can be used with PHP projects I won't go that way for the two reasons:
Don't want to part with phpdoc comments in my PHP classes or add something JSDuck-specific in there;
Don't really need the whole JSDuck doc interface as I am going to create a very custom one myself;
Prefer a PHP solution.
After half a day spent on phpdoc2 I finally found a solution which I believe is the right one. One should not worry or even know about Abstract Syntax Tree XML in phpdoc2 to achieve the goal.
The solution is:
Create a new writer class Json.php and place it in src/phpDocumentor/Plugin/Core/Transformer/Writer/ along with other writers. A good start point is to take the Graph.php writer and rewrite it to output JSON instead of SVG;
Create and use a new simple template like:
<?xml version="1.0" encoding="utf-8"?>
<template>
<transformations>
<transformation writer="Json" artifact="classes.json" />
</transformations>
</template>
Add Json writer to src/phpDocumentor/Plugin/Core/ServiceProvider.php's register method:
$writerCollection['Json'] = new Writer\Json();
And finally, just use the template when calling phpdoc on your project.

Can I avoid Microsoft.XMLDOM parsing error with different dtd or schema?

I am getting various parse errors using loadXML. Is there some way I can set a less strict dtd or something like that?
Code being loaded:
<h3 id="group_text" class="groupbox_header_text" style="margin-top:0px;margin-bottom:0px;">Time & Day</h3>
Failed for reason:
reason "Whitespace is not allowed at this location."
I think this is because of the & symbol.
Thanks,
Grae
No. You can only use an XML parser to parse XML. Your input is not well-formed XML. Your only options are to (a) change the input to be well formed XML; or (b) not use an XML parser. i.e. use an HTML parser instead.

SAXParseException: Element type SOAP:Text must be followed by either attribute specifications, ">" or "/>"

I'm attempting to read a response from a web service call in a junit test running in Eclipse Galileo. I'm able to successfully receive responses except when the response is a SOAP fault. Then I get the following exception:
org.xml.sax.SAXParseException: Element type "SOAP:Text" must be followed by either attribute specifications, ">" or "/>"
I have validated the XML in LiquidXML Studio against the SOAP 1.2 schema and it checks out.
Here is the XML response that SAX appears to be choking on. It has been stripped to the minimum in an attempt to eliminate anything obvious (I even made sure it didn't have any self closing elements):
<SOAP:Envelope xmlns:SOAP="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP_ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP:Header>
</SOAP:Header>
<SOAP:Body>
<SOAP:Fault>
<SOAP:Code>
<SOAP:Value>SOAP:Sender</SOAP:Value>
<SOAP:Subcode>
<SOAP:Value>SOAP:Sender</SOAP:Value>
</SOAP:Subcode>
</SOAP:Code>
<SOAP:Reason>
<SOAP:Text xml:lang="">
</SOAP:Text>
</SOAP:Reason>
<SOAP:Node>
</SOAP:Node>
<SOAP:Role>
</SOAP:Role>
<SOAP:Detail>
</SOAP:Detail>
</SOAP:Fault>
</SOAP:Body>
</SOAP:Envelope>
Any help would be appreciated.
Its obviously not regcognising 'xml:lang=""' as an attribute. CHeck with your xsd or xmlSchema what attributes are valid. Also you should be using
xml:lang=""
rather than "" although most parsers forgive you for this.
I think the problem is in mapping the soap fault xml to its corresponding object.
It turns out the problem was related to a tool I was using to return static string responses to web service requests. The static response XML contained the xml:lang attribute. However, when the tool was returning the static string, it was modifying it on the way out and replacing xml:lang on-the-fly with the fully qualified namespace equivalent {http://www.w3.org/XML/1998/namespace}lang. When this response was received, the SAXParser was choking because it couldn't interpret the fully qualified equivalent.
The tool returning the static responses used a Groovy xml parser as an integral part of sending the response.
The XmlParser Groovy class has a constructor that I had to change to set validating and namespaceAware attributes to false. So instead of XmlParser(), the tool now calls XmlParser(false, false).
Problem solved.
Thanks for the responses.