python connector.xml include file

3 posts / 0 new
Last post
Offline
Last seen: 2 years 5 months ago
Joined: 08/12/2021
Posts: 14
python connector.xml include file

I've seen similar questions on the forum, but not the exact problem I'm having, so I decided to make a new post.

Using python connector, I have a connector.xml,, and 2 rti generated files (idl to xml), foo.xml, and fooDefs.xml.  foo.xml contains a "<include file="fooDefs.xml">  

This works fine:

folder/connector.xml
folder/foo.xml
folder/fooDefs.xml

connector.xml:
<types>
  <include file="foo.xml/>
</types>

 

But the following results in: DDS_XMLFileInfoList_assertFile:!open file: xml/fooDefs.xml.  

I believe the reason it fails is bcause foo.xml contains the following
<include file="fooDefs.xml">

folder/connector.xml
folder/xml/foo.xml
folder/xml/fooDefs.xml

connector.xml
<types>
  <include file="xml/foo.xml/>
</types>

It seems the "include file=" that is in foo.xml is expected to be relative to the connector.xml location.  Is there a way around this, other than putting the connector.xml and all the type xml files in the same folder?  Both foo.xml and fooDefs.xml are auto generated by rti, so I don't want to modify the "include file=" if I don't have to.

Thanks!
Bobby

 

 

gianpiero's picture
Offline
Last seen: 3 months 12 hours ago
Joined: 06/02/2010
Posts: 177

Hello Bobby,

Sorry for the late response. I verified your use case with an example of my own:

  1. I have a writer.py that loads connector.xml (they both live in the top level dir)
  2. connector.xml has <include file="xmlfiles/shapetype.xml"/>
  3. and xmlfiles/shapetype.xml has <include file="fill.xml"/>
  4. fill.xml lives in xmlfiles/ alongside shapetype.xml
This fails to load because the xml parser (used by connector) says it cannot find fill.xml
 
If I change xmlfiles/shapetype.xml to have <include file="xmlfiles/fill.xml"/> then it works.
 
I wanted to verify that this was an issue with the xml parser and not with connector. I tried with a standard c++ application and i have the same result:
 
I created a C++ application that loads an XML file USER_QOS_PROFILES.xml that <include file="xmltypes/mytype.xml"/> and then in xmltypes/mytype.xml i have an <include file="consts.xml"/>. I get the same issue. If I change the last include in xmltypes/mytype.xml to be <include file="xmltypes/consts.xml"/> everything works.
 
I think your analysis is almost correct: the xml parser looks for files using a relative path but I don't thinlk is relative to where connector.xml is BUT is relative to the CURRENT WORKING DIRECTORY.
 
So if you think of the first example in python above, I have the following directory structure
 
- writer.py
- connector.xml
+ xmlfiles/
	- fill.xml
	- shapetype.xml

 

In order to have the include in shapetype.xml to stay <include file="fill.xml"/> you have to start from the xmlfiles/ directory
 
cd xmltypes
python ../writer.py

 

This seems to we working for me because now all the path in the files stored in xmlfiles are relative to the CWD and CWD=xmlfiles. The file connector.xml is loaded anyway because when i load it in the python script i give the full path:

with rti.open_connector(
        config_name="MyParticipantLibrary::MyPubParticipant",
        url=file_path + "/connector.xml") as connector:

Where file_path is:

 

file_path = os_path.dirname(os_path.realpath(__file__))

 

Just as a future reference, the issue that you experiencing, has already a Jira ticket assigned (CORE-11732)

 

I hope this workaround helps for now.

Best,

  Gianpiero

 

Offline
Last seen: 2 years 5 months ago
Joined: 08/12/2021
Posts: 14

Thanks Gianpiero for the very thorough explanation.  I was worried that I'd have to keep my connector.xml in the same folder as my types.xml, but I see that is not the case.  

The workaround you described does help.

Thanks!
Bobby