简体   繁体   中英

C++ Expat prints only first letter of element and of data in tags

I am using Visual Studio 2017 and am learning to work with Expat (no option for using another XML parsing library at the moment) for the purpose of writing a function that will receive the tags nested in an XML tag and retrieving the string content of one of these tags.

So, if the XML looks like this:

<doc>
    <aa>bla</aa>
    <bb>
        <cc>cookie</cc>
        <dd>dog</dd>
        <ee>easy</ee>
    </bb>
    <foo>bar</foo>
</doc>

My function will receive the content of like this:

<cc>cookie</cc>
<dd>dog</dd>
<ee>easy</ee>

And the function will also receive the name of the tag we want the content of, so if the tag is my function will return "dog".

I am somewhat new in C++ and have no experience with C at all. I found three different code samples here in Stack Overflow, which basically inherit from Expat's outline.c . The samples are from this , this and this post.

When I run the code samples from all three of these very different samples, I get the same phenomena - instead of printing out the full name of the tag or the full content of the tag, the only thing that's being printed in all three samples is the first character of the tag or the string.

For example, this post takes this XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

and prints out

-- Note --<br> 
To:  Tove<br>
From: Jani<br>
Heading: Reminder<br>
Message: Don't forget me this weekend!<br>
<br>

What I get when I run the code sample from this post with the same XML is:

 T<br>
 J<br>
 R<br>
 D<br>
<br>

At first I thought there must be something wrong with the code samples and simply moved on to the next one. But this is consistent so there must be something wrong with my setup. I'm afraid I'm too inexperienced to know what it is that is wrong.

Thanks in advance.

The problem was that I thought I'd use Expat's unicode-supporting dlls because that was I'll be prepared for whatever can come my way. So expat read the second byte in the first character in every element or tag content and thought that its emptiness means that's the end of the whole thing and moved on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM