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

loading a valid XML from a URL gives empty data #52

Open
ioweb-gr opened this issue Oct 6, 2020 · 4 comments
Open

loading a valid XML from a URL gives empty data #52

ioweb-gr opened this issue Oct 6, 2020 · 4 comments

Comments

@ioweb-gr
Copy link

ioweb-gr commented Oct 6, 2020

I'm trying to load an XML from a URL however it's not loading correctly using fluidxml

URL is https://www.yourstaging.eu/products.xml

$doc = \FluidXml\FluidXml::load('https://www.yourstaging.eu/products.xml');
        $productsNode = $doc->query("//products");
        $productNodes = $doc->query("//products/product");
        $loadedData = $doc->xml();

Both queries return 0 nodes and the resulting xml is empty.

I'm not sure why this is happening.

xmlstarlet finds the file is valid xml.

@ioweb-gr
Copy link
Author

ioweb-gr commented Oct 6, 2020

I think the problem is the huge size of the XML file because usingle simplexml_load_string will only work if I add the

LIBXML_COMPACT | LIBXML_PARSEHUGE options

@ioweb-gr
Copy link
Author

ioweb-gr commented Dec 18, 2020

@daniele-orlando Could you please explain why you don't think this is an issue? I think fluidxml should provide a way to handle big files. How can I work around this limitation?

@daniele-orlando
Copy link
Member

daniele-orlando commented Dec 18, 2020

Sorry for the wrong handling of this ticket. 😓

FluidXML uses DOMDocument which in turn uses libxml for parsing XML.

It's 100% an error due to the default limits of libxml, which can be relaxed as you noted using the LIBXML_PARSEHUGE and LIBXML_COMPACT.

Handling the libxml flags requires an integration of the load API, the implementation of the tests and the update of the documentation. Due to my busy schedule, it could take some time.

I could enable those flags by default in the future, but it has to be considered as a breaking change because it changes the behaviour of the library which could exhaust the memory of a server.

I reopen the ticket, marking it as a request for a feature.

In the meantime, you can import the file with DOMDocument/simplexml and then import it inside fluidxml.

$xml = file_get_contents('https://www.yourstaging.eu/products.xml');
$dom = new DOMDocument();
$dom->loadXML($xml, LIBXML_PARSEHUGE | LIBXML_COMPACT);
$doc = new FluidXml($dom);

Thanks for getting time to report the issue and please, let me know if the workaround does solve the issue in the meantime.

@ioweb-gr
Copy link
Author

Hi @daniele-orlando . It's no problem at all this part. In my case I changed the code to use LIBXML directly for my needs but I reported this issue because I found it restricting not being able to set the parse flags as I mentioned.

It's not something that needs to be done urgently or anything and I think you're right to mark it as an enhancement. But I also think it will be great to document it in the readme.

When I find free time I'll also test the workaround to tell if it works or not and hopefully you can add it to a troubleshooting section in the readme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants