Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I have to store data from xml file in sql server using ms access VBA. This part is simple. Where i am getting stuck is that one of the values that i have to enter in db is in comment in xml file an i don't know how to read the comment.
I googled and all i could find there is examples in c# or java.

XML
<!--  status 10-04-2015 10:19 -->
<repair><ref>111111</ref>
<repair_number1>1234445</repair_number1>
<repair_number2>xxx011</repair_number2>
<status_code>X.2</status_code>
<status_description>X.2 : xxxxxxxxxxxxxxxxxxxx</status_description>
</repair>
</repair_status>


Please tell me how will i read the date-time in the comments in xml file

What I have tried:

there is nothing that i could try as i couldn't find any source on Google from where i could take some inspiration
Posted
Updated 29-Apr-16 8:19am
v2
Comments
Sergey Alexandrovich Kryukov 29-Apr-16 13:32pm    
Read carefully: What have you tried so far?
Is it more clear now?
—SA
Sergey Alexandrovich Kryukov 29-Apr-16 14:20pm    
I just removed my answer for .NET; I failed to notice your "VBA" tag. But should you rather use .NET, instead of obsolete and unpleasant to work with stuff, I can write it again for you.
—SA
Patrice T 30-Apr-16 11:02am    
What have you tried apart from Googling for a full blow up solution ?
If you are a programmer, can't you device a solution by yourself ?
It is only about reading a text file.

1 solution

Unfortunately, I also faced the requirement to read and accommodate comment data in XML. This is a really nasty practice which should be eliminated by all means. At that time, I managed to fight back and deny such requirements.

But what to do if you, unfortunately, cannot avoid this kind of work?

One of the ways to parse with VBA (why? why?! why not VB.NET?) with ancient MSXML would be using its SAX2. As you can see, this approach can extract comments for you: Simple API for XML — Wikipedia, the free encyclopedia[^].

Please start here:
MSXML[^],
SAX2[^],
https://msdn.microsoft.com/en-us/library/ms757033%28v=vs.85%29.aspx[^],
Create a Simple Filter[^].

The idea is: SAX provides a very efficient forward-only interface to parse the whole thing from the beginning to the end. In the road, you can collect some elements and ignore other; you can figure out current context of each element and other criteria, and decide if you need it, if if you do, add required data to some internal collection.

In normal practice, comment is one of the element types to be always ignored. Wish you the same. But as you can see, this information can be preserved for you. :-)

I gladly credit Richard Deeming for his comment on my previous solution. I wrote a solution for .NET, but he pointed out my mistake and suggested to look for MSXML, provided appropriate link.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900