Pugixml: No document element found - c++

I'm having some trouble loading the document (see link http://pastebin.com/FE3nDX9h) in pugixml.
I'm getting an error code of 16: No document element found which indicates that the XML file is invalid or empty which I think is neither.
I am using the default parsing method. Is there something I am missing?
edit: as requested heres some source code http://pastebin.com/USUjLC4q you will need to edit the paths.

You need xml_document::load_file but xml_document::load.
From pugi documentation:
There is also a simple helper function, xml_document::load, for cases when you want to load the XML document from null-terminated character string.
So, load's argument has to be xml by itself, not file name.

Related

ColdFusion CF2021 xmlParse(file) returning wddx encoded object

UPDATE: After doing some more poking around, it looks as though the problem has to do with where CF is looking for the DTD file referenced in the XML.
We have the DTDs, but it looks as though CF isn't finding them, so it isn't sure how to parse the XML according to the DTD. I determined this by having it parse XML without any DTD, and it worked as expected and as I wanted - returning a parsed xmlDoc, not a string.
Is there some way of setting the default directory for where CF should look for the DTD specified in the XML?
We're running CF2021, and xmlParse(file), which should return a parsed XML object is instead returning the file contents as a string, inside a wddx encoded object. We have just migrated from a CF2018 server running on a remote hosting service to CF2021 running on an AWS box.
In order to return the XML object we need, I need to run xmlParse on the file, then wddx2cfml on the object, then xmlParse again on the string.
Is there a reason why xmlParse, which should return a parsed XML object, is instead behaving this way?
We pass the system file location to the method. Call it docPath, and it'd look something like g:\appName\xmlFiles\20230125.xml
Then we have, in cfscript:
doc = xmlParse(docPath);
When I dump that to a file, I get what I described above. When I change it to the following, I get what want:
docFile = xmlParse(docPath); cfwddx(action="wddx2cfml", input="#docFile#", output="xmlString"); xmlDoc = xmlParse(xmlString);
But I don't understand why this is necessary, and I'm concerned about having to change it everywhere in the code that we use xmlParse. For the record, this also occurs in tagged CF as well as cfscript, so it's not that.
Putting the dtd files in CF's WEB-INF folder solved the problem. CF was able to match the DTD with the DOCTYPE and properly parse the XML.

Is it possible to pass a file path to setStyleSheet() in Qt

I found the following code in obs-studio:
obs-studio/UI/obs-app.cpp
QString mpath = QString("file:///") + path.c_str();
setStyleSheet(mpath);
A file path preceded by file:/// is passed directly to setStyleSheet().
This usage is not mentioned in the official reference. However, obs-studio doesn't redefine this function, indicating that it is a Qt functionality.
Is this supposed to work? I tried it in my code but failed.
If you look at the Qt documentation there is no indication of supporting any URL to be passed as an argument to setStyleSheet(). Furthermore, if you look at the definition of QApplication::setStyleSheet, there is no URL handling.
The stylesheet is proxied by a QStyleSheetStyle object. Within that object, you will find that the string ends up at this method of the CSS parser. The functionality to read a file is there indeed.
The logic to treat the string's content as a file path instead of stylesheet markup can be found here. The file:/// part, if present, is removed and the string is then understood to be a path.
However to me it seems to be an undocumented feature and therefore better be avoided.

Regex or Xpath for extracting nodes?

I have an XML file with the following structure;
<JobList>
<Job><subnodes/></Job>
<Job><subnodes/></Job>
</JobList>
This xml can be broken sometimes leaving a missing ending of <JobList> and missing end of </Job>.
I would like to be able to extract the <Job> nodes with full content on those that are closed with </Job>. What is the best way to do this?
To make a long story short I am using .NET and built in serializers for deserializing xml content. But since new properties are added you cannot just go back and forth between different versions as it is to strict. Mostly it works, but I would like to have a backup recovery method for this - hence the question.
The current situation is that the deserializer "crashes" the whole deserializing when a new property has been added instead of ignoring it. I am looking to manually parse it on error.
As mentioned on the comments, the ideal would be to make the xml valid, if for whatever reason that is not possible, the workaround is parsing the file as text with a regex.
A general regex for this case could be something like:
<Job>((?!<Job>).)*</Job>$
this will bring anything between a complete pair
Please notice that this will also return nodes with 'broken' inner nodes, but according to your question you are only concerned about missing and tags.

MarkLogic: Trying to understand error "Node has complex type with non-mixed complex content"

I'm getting this error during pipeline processing of an xml document, the processing does an xslt transform. It appears to be telling me that the document is in some way invalid, however the document passes validation against the xsd in Oxygen.
First, the error is not telling me the line number in the offending data file, just the line number in the pipeline xqy file, from what I can tell.
Second: The error is grammatically non-sensical to me: It seems to say that a node in the document is defined as a complex type, but that content in the document is non-mixed...why would that matter? Most content is non-mixed, right? So non-mixed content is as I see it sort of the norm in most xml that I see. Thanks.
The error can also occur when some function is expecting a more simple value as argument, but receiving complex element types.
Actually, searching in the archives at http://marklogic.markmail.org/ the error seems to be coming from fn:data() if it is passed 'too' complex values to put it briefly. I think the message is meant to say that the node that is being passed in doesn't have a typed value. See also here: http://www.w3.org/TR/xpath-functions/#func-data
If you provide the full error message, we might be able to help you out..
The document is likely valid, but it doesn't conform to expectations in your XSLT code. Without seeing code and document, muy hunch is that the XSLT is expecting the matching document node to be an element (or similar) but it is an attribute or text node.

c++ XML file parsing problem

Can any one tell me how to change an xml file using c++ and xercesc code?
My file is on my desktop using .
I know c++ file handling but don't know how to change attribute of xml file.
Can anybody tell me what I should do?
Any example, tutorial, book, etc., which can help me will be cordially accepted.
You can modify an attribute using the setAttribute function of class DomElement, as documentation says:
If an attribute with that name is already present in the element, its value is changed to be that of the value parameter.