Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot load anything in MXML and how to debug the problem?? #327

Open
DISAPPEARED13 opened this issue May 25, 2024 · 6 comments
Open

Cannot load anything in MXML and how to debug the problem?? #327

DISAPPEARED13 opened this issue May 25, 2024 · 6 comments
Assignees
Labels
investigating Investigating the issue question General usage question

Comments

@DISAPPEARED13
Copy link

I tried tol load xmls with mxmlLoadFile(NULL, fp, MXML_OPAQUE_CALLBACK);, but got 0x0000000000000000 <NULL> as result.
The whole XMLLoad is liked this:

	wCharSet cs;
	const char* filename = (const char*)cs.conv(WCS_LOCAL, pwzFileName, WCS_UNICODE);
	FILE* fp = NULL;
	if ((fp = fopen(filename, "r")) == NULL) {
		return false;
	}

	Free();
	m_pXmlRoot = mxmlLoadFile(NULL, fp, MXML_OPAQUE_CALLBACK);
	fclose(fp);

as I seen that filename can be opened and the fp is like 0x0000017a365acfa0 {_Placeholder=0x0000000000000000 }, I checked lots of information that the result means that the file can be opened successfully, and the XML file used to be read before, and no changes happened.
So, could you please tell me how to find out the real reason for why I cannot load XML with mxmlLoadFile??

My operation system is Windows10 and Visual Studio 2017, with MXML 2.9

BTW, could you tell me how to update MXML 2.9 to MXML4? I checked the log that MXML4 seems quite different from MXML3(might be also 2.9), I tried to replace the direction of dll and libs and shows that mxml_node_s is not fit for mxml_node_t.

Great thanks again!

@michaelrsweet
Copy link
Owner

It would be useful to see a sample XML file you are trying to load. Also, the default error callback will send any error messages off to stderr, so if you do this from a console application you'll be able to see those errors. (regular applications don't have a console so you'd need to provide your own error callback to see the messages...)

Also, the struct mxml_node_s type became fully private in Mini-XML 3 - even for Mini-XML 2.x you should be using the provided accessor functions.

Finally, Mini-XML 4 is available as source. Your own code will require some conversion to it but the migration guide that is part of the documentation should point you in the right direction.

@michaelrsweet michaelrsweet self-assigned this May 25, 2024
@michaelrsweet michaelrsweet added question General usage question investigating Investigating the issue labels May 25, 2024
@DISAPPEARED13
Copy link
Author

Thanks for your reply! I tried to run the code compiled in Visual Studio, but not any errors came back, just cannot corrrectly get the XML content. Here is the content from 'tag.xml', one of my XML(yes...every XMLs cannot be read in my code...very sad):

<?xml version="1.0" encoding="utf-8"?><masses><mass name="top_left"
align_horz="near" align_vert="far" sort_descend="true"><item
tag="0010,1010" /><item tag="0010,0020" /><item tag="0010,0010" /></mass><mass
name="top_right" align_horz="far" align_vert="far" sort_descend="true"><item
tag="0008,0070" /><item tag="0008,1090" /><item tag="0008,0020" /></mass><mass
name="bottom_left" align_horz="near" align_vert="near"
sort_descend="false"><item tag="0018,0060" /><item tag="0018,7030" /></mass><mass
name="bottom_right" align_horz="far" align_vert="near"
sort_descend="false"><item tag="0028,1051" /><item tag="0018,0050" /><item
tag="0020,0013" /></mass></masses>

Thanks for your advice for accessing the structure, I would get more information from the migration guide!

@DISAPPEARED13
Copy link
Author

Hi there! Thanks for your patience... But I still have some problems like this, I tried to simplify my problems to find out what's happening in my scene. And run with MXML4.0, With writing some test code like these:

#include <iostream>
#include <mxml.h>

void errorCallback(const char* message) {
	fprintf(stderr, "XML parsing error: %s\n", message);
}

int main()
{
	const char* filename = (const char*)"example.xml";

	FILE* fp = NULL;
	fp = fopen(filename, "r");

	mxml_node_t* tree = mxmlNewXML("1.0");
	mxml_options_t *options = mxmlOptionsNew();
	mxmlOptionsSetTypeValue(options, MXML_TYPE_OPAQUE);

	tree = mxmlLoadFilename(NULL, options, filename);

	if (!tree) {
		fprintf(stderr, "Failed to load XML file: %s\n", filename);
		return 1;
	}

	fprintf(stderr, "Element::%s\n", mxmlGetElement(tree));
	fprintf(stderr, "Value::%s\n", mxmlGetText(tree, 0));

	mxmlDelete(tree);

	std::cout << "Hello World!\n";
}

But the console shows:

Element::(null)
Value::(null)

And the example.xml I've tried is from your document website like this:

<?xml version="1.0" encoding="utf-8"?>
<data>
    <node>val1</node>
    <node>val2</node>
    <node>val3</node>
    <group>
        <node>val4</node>
        <node>val5</node>
        <node>val6</node>
    </group>
    <node>val7</node>
    <node>val8</node>
</data>

@DISAPPEARED13
Copy link
Author

DISAPPEARED13 commented May 31, 2024

For resetting the callback output of the console, I found that there are different RANDOM errors comes out when mxmlLoadFile, here are the outputs I saw.

1. just failed loading files

2. "mxml: Bad control character 0x00 not allowed by XML standard!"

(but I opened the file in Notepad++ and display every symbol and got nothing wrong.)

3. "mxml: Mismatched close tag </xxx> under parent <?xml version="1.0" encoding="utf-8"?>!" or "mxml: Mismatched close tag </xxx> under parent </null>!"

but the declaration is necessary, seems failed to load the correct tag? but the file is not encrypted I am sure.

4. "mxml: <tag2> cannot be a second root node after <tag1>"

I search the xml and nothing wrong.

@michaelrsweet
Copy link
Owner

I really have no guidance here. If you can attach an actual file to this issue I might be able to look at that, but my only guess is that there is some sort of character encoding issue that is giving Mini-XML trouble. For the record (and this is documented in many places), Mini-XML only supports reading UTF-8 and UTF-16 encoded XML and only supports writing UTF-8 encoded XML.

@DISAPPEARED13
Copy link
Author

DISAPPEARED13 commented Jun 3, 2024

Here is the XML loading code which is not work.

#include <iostream>
#include <mxml.h>

void errorCallback(const char* message) {
	fprintf(stderr, "XML parsing error: %s\n", message);
}

int main() {
	const char* filename = "example.xml";

	FILE* fp = fopen(filename, "r");
	if (!fp) {
		perror("Error opening file");
		return 1;
	}

	std::cout << "File opened successfully." << std::endl;

	char ch;
	while ((ch = fgetc(fp)) != EOF) {
		putchar(ch);
	}
	rewind(fp); 

	fprintf(stderr, "\n-------------------------------------------------------------------------------\n");

	mxml_node_t* tree = mxmlLoadFile(NULL, fp, MXML_OPAQUE_CALLBACK);
	fclose(fp);

	if (!tree) {
		fprintf(stderr, "Failed to load XML file: %s\n", filename);
		return 1;
	}

	mxml_node_t* root = mxmlFindElement(tree, tree, "data", NULL, NULL, MXML_DESCEND);
	if (!root) {
		fprintf(stderr, "Failed to find root element\n");
		mxmlDelete(tree);
		return 1;
	}

	for (mxml_node_t* node = mxmlFindElement(root, root, "node", NULL, NULL, MXML_DESCEND);
		node != NULL;
		node = mxmlFindElement(node, root, "node", NULL, NULL, MXML_NO_DESCEND)) {
		fprintf(stdout, "Element::%s\n", mxmlGetElement(node));
		fprintf(stdout, "Value::%s\n", mxmlGetOpaque(node));
	}

	mxmlDelete(tree);

	std::cout << "Hello World!\n";
	return 0;
}

Here is the XML file. But I saved it as UTF-8 file. I tried to fix the problem by saving it as ASCII file and then re-save it as UTF-8, but still unwork...
example.zip

Great Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigating Investigating the issue question General usage question
Projects
None yet
Development

No branches or pull requests

2 participants