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

DOMDocument throwing empty source validation error #29

Open
zainavrillo534102 opened this issue Jul 23, 2024 · 3 comments
Open

DOMDocument throwing empty source validation error #29

zainavrillo534102 opened this issue Jul 23, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@zainavrillo534102
Copy link

zainavrillo534102 commented Jul 23, 2024

I have an issue today where i was trying to fetch an xml data from soap API. When i tried to use that data and tried to convert it using XML wrangler getting below error . I event tried to validate the xml through the custom DOMDocument class usage and it shows its valid and okay.

function isValidXml($xml): bool
    {
        libxml_use_internal_errors(true);
        $doc = new \DOMDocument();
        $isValid = $doc->loadXML($xml);
        if (!$isValid) {
            $errors = libxml_get_errors();
            foreach ($errors as $error) {
                Log::error('XML Error: ' . $error->message);
            }
            libxml_clear_errors();
        }
        return $isValid;
    }

alueError: DOMDocument::loadXML(): Argument #1 ($source) must not be empty in /home/forge/proclaim.avrillo.co.uk/vendor/veewee/xml/src/Xml/Dom/Loader/xml_string_loader.php:18
--
Stack trace:
#0 /home/forge/proclaim.avrillo.co.uk/vendor/veewee/xml/src/Xml/Dom/Loader/xml_string_loader.php(18): DOMDocument->loadXML()
#1 /home/forge/proclaim.avrillo.co.uk/vendor/veewee/xml/src/Xml/Dom/Loader/load.php(20): VeeWee\Xml\Dom\Loader\{closure}()
#2 /home/forge/proclaim.avrillo.co.uk/vendor/azjezz/psl/src/Psl/Result/wrap.php(23): VeeWee\Xml\Dom\Loader\{closure}()

To Reproduce

  1. Due to senitivity i can't give the xml here as it contains the attachment base64 but when i used this package with the same incoming xml it does not gave any error
    This was my code snippet
 return XmlReader::fromString($this->xmlData)->removeNamespaces()->values();
@Sammyjo20
Copy link
Member

Hey @zainavrillo534102 thanks for raising this issue with me. I have also found this happen when the XML is slightly invalid, or if you want to parse a subset of HTML/XML. I will mention with the maintainer of veewee/xml and see if I can get a new option that reduces some of the validation.

@veewee I hope you are well! I've had this issue a few times, especially when I want to parse just a small part of HTML like <p>Hello</p>. (Overly simplified I know) but when I use DOMDocument directly it doesn't throw any errors. Is there a configuration option in the reader so it accepts anything assuming it looks like valid XML/HTML?

@Sammyjo20 Sammyjo20 added the bug Something isn't working label Aug 3, 2024
@veewee
Copy link
Collaborator

veewee commented Aug 3, 2024

The error from the initial post is quite clear: an empty string is being loaded as XML which is invalid. This error is being thrown by PHPs Dom document. So one of the methods that are being called is resulting in an empty string I suppose.

Would it be possible to create a simplified reproducer with truncated data @zainavrillo534102 ?

@Sammyjo20 the XML library parses XML, not HTML. I don't know if the XML reader extension supports that dialect. Maybe also for that issue, a reproducer would be nice in order to understand what you are trying to do.

@Sammyjo20
Copy link
Member

Thank you for the very quick reply! Noted about the HTML - I kind of assumed because it looked XML-ish, the reader would understand it, but I won't try and use it for HTML in the future.

In regards to fixing this specific issue if you are able to give us a string that reproduces this issue that would be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants