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

New User questions... #327

Open
KeithProctor opened this issue Jun 1, 2023 · 5 comments
Open

New User questions... #327

KeithProctor opened this issue Jun 1, 2023 · 5 comments

Comments

@KeithProctor
Copy link

KeithProctor commented Jun 1, 2023

Love that you created this tool so TY up front. I'm having the following issues:

  1. How do you not add the # and @ characters being prepended to the name of a name value pair?
  2. Is there a way to efficiently deal with paths? I want to do something like this.

I know this is invalid... Just showing a concept here:

`basePath = ['FMSaveAsXML']
structPath = [basePath]['Structure']
layPath = structPath['LayoutCatalog'] # want an iterable pointer to this location

print ( 'Ver: ' + str(basePath['@Version']))
print ( 'layout: ' + str(layPath[0]['LayoutName']))
`

@KeithProctor
Copy link
Author

@martinblech I've created a function to walk over a list. The call simplifies things but I consider the function itself a hack. It's ~30 lines long. So I do something like:

GetXMLData( xml, basePath + ['path2', 'path3'])

So the real question now is... is there a better way?

@bfontaine
Copy link

Please share a sample XML so we can reproduce your issue.

@KeithProctor
Copy link
Author

KeithProctor commented Jul 7, 2023 via email

@bfontaine
Copy link

(I’m just another user of xmltodict, I’m not the maintainer)

If your XML contains only a single field of each tag, you could use theDict["path1"]["path2"]["path3"]. If it doesn’t or you don’t know in advance, it becomes tricky because each intermediate element can be either be a dict or a list of dicts.

As far as I know, xmltodict just parses the XML into a dict; it doesn’t offer any way to traverse that dict. There are other libraries that offer that kind of feature (lxml is probably the most popular) but if you already use xmltodict it might be overkill to change libraries just for that. If you search for "nested dict" on StackOverflow you might be able to find a suitable solution (see here for example).

@KeithProctor
Copy link
Author

KeithProctor commented Jul 7, 2023 via email

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

No branches or pull requests

2 participants