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

XInclude processing #207

Closed
hcw70 opened this issue Jul 9, 2020 · 7 comments
Closed

XInclude processing #207

hcw70 opened this issue Jul 9, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@hcw70
Copy link

hcw70 commented Jul 9, 2020

Dear authors of xsdata.

I need to process a XML document which is assembled from others by means of XInclude
(http://www.w3.org/2001/XInclude).

LibXML and python seems to handle that, but via xsdata it does not work with this.

<?xml version="1.0" encoding="UTF-8"?>
<MessageDB xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xxx.de/config/xxx msgdb/xsd/MessageDB.xsd"
    xmlns="http://xxx.de/config/xxx"
    xmlns:xi="http://www.w3.org/2001/XInclude">
    
    <xi:include href="MessageDB-Example-lib.xml"/>
    
    <module name="MotivatinExample1">
   </module>
 </MessageDB>

Maybe it is sufficient to follow one of:
https://lxml.de/1.3/api.html#xinclude-and-elementinclude

or
http://effbot.org/zone/element-xinclude.htm
?

Maybe it would be good to have that as a ParserConfig option?

@tefra tefra added the enhancement New feature or request label Jul 9, 2020
@tefra
Copy link
Owner

tefra commented Jul 9, 2020

I need to read more on this but it looks interesting, can you share the original schema as well?

Maybe that's easier to integrate than it looks...

@hcw70
Copy link
Author

hcw70 commented Jul 10, 2020

The actual schema is not important.
How it works is that the XML processor reads the pointed-to file and puts it into the xinclude location.
If you are using lxml or elementtree this should be that simple as given in the links.

Read http://www.w3.org/2001/XInclude , thats not a long standard, and realizes by some xml parsers already.

@tefra
Copy link
Owner

tefra commented Jul 10, 2020

The XmlParser is using the lxml.etree.iterparse

def parse(self, source: io.BytesIO, clazz: Type[T]) -> T:

Do you know if the lxml xinclude is supported with iterparse?

@hcw70
Copy link
Author

hcw70 commented Jul 10, 2020

Dunno. Maybe just try to do like this (from the lxml link)

tree = etree.parse(data)
tree.xinclude()

@tefra
Copy link
Owner

tefra commented Jul 10, 2020

Yeah I don't want to switch from iterparse to parse for performance reasons, but let me check if there is a workaround...

@tefra
Copy link
Owner

tefra commented Jul 11, 2020

Hey @hcw70 give it a try pr #210 let me know how it works for you 🧪

The pr is now merged on master and will be included in the new release until then you can install from master

@hcw70
Copy link
Author

hcw70 commented Aug 1, 2020

@tefra The diff looks great! I will give it a try after my vacation. Thanks for fixing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants