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

Does not handle processing instructions #30

Open
pecostm32 opened this issue May 29, 2022 · 5 comments
Open

Does not handle processing instructions #30

pecostm32 opened this issue May 29, 2022 · 5 comments

Comments

@pecostm32
Copy link

Next to not handling comments it also does not recognize processing instructions.

An easy way to overcome this is to use a do while loop in the node parsing like so:
//Need a do while loop to find a proper top tag and allow skipping of processing instructions or comments
do
{
/* Parse open tag
*/
tag_open = xml_parse_tag_open(parser);

if (!tag_open)
{
  xml_parser_error(parser, NO_CHARACTER, "xml_parse_node::tag_open");
  goto exit_failure;
}

original_length = tag_open->length;
attributes = xml_find_attributes(parser, tag_open);

//Check if the tag is a processing instruction or a comment
if((tag_open->length > 0) && ('?' == tag_open->buffer[0]) || (('!' == tag_open->buffer[0]) && ('-' == tag_open->buffer[1]) && ('-' == tag_open->buffer[2])))
{
  //Drop the found processing instruction or comment
  xml_string_free(tag_open);

  //Reset the tag_open pointer to force scanning for the next one
  tag_open = 0;
  
  if(attributes)
  {
    //Need to free attributes!!!!!! also in error handling!!!!! 
  }
}

} while(!tag_open);

Another issue is the freeing of the attributes.

@ooxi
Copy link
Owner

ooxi commented May 29, 2022

Thanks for reaching out! Could you provide an example of missing attribute freeing? Preferably a patch :-)

@pecostm32
Copy link
Author

Attached is what I made of it. You already had a xml_attribute_free which was used in xml_node_free. I added a xml_attributes_free function which is called in the xml_parse_node function when needed

xml.c.zip

@ooxi
Copy link
Owner

ooxi commented May 29, 2022

Thanks @pecostm32, could you provide an xml fragment which is handled by this code?

@pecostm32
Copy link
Author

This is the file I'm working with
GD32E230xx.svd.zip

@ooxi
Copy link
Owner

ooxi commented Jun 8, 2022

@pecostm32 to make sure I understand you correctly: Are you just concerned with <?xml version="1.0" encoding="utf-8" standalone="no"?>?

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