In libxml2, I can easily find the source line that an xmlNode came from (xmlNode::line), but I can't see how to find the name of the file that it came from. This is especially useful when the loaded document contains XInclude directives. While I can think of manual ways of handling this (look for xml:base attribute above the given node; manually store the file name and use that if xml:base is not set), I'd rather use something built into libxml2.
Is there a function for retrieving the file name from which any given xmlNode object was loaded?
Doesn't look like it. Documentation for xmlDocPtr says that name is "name/filename/URI of the document", but this isn't getting populated in my tests with xmlReadFile.
Looking through the code, it looks like the filename isn't saved in the doc, and the parser context disappears at the end of parser.c's xmlDoRead().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With