Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get source file name from an xmlNode?

Tags:

c

libxml2

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?

like image 259
Nathan Avatar asked Mar 17 '26 03:03

Nathan


1 Answers

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().

like image 91
Jason Viers Avatar answered Mar 18 '26 23:03

Jason Viers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!