简体   繁体   English

C++ Expat 仅打印标签中元素和数据的首字母

[英]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.我正在使用Visual Studio 2017,并且正在学习与Expat合作(当时使用另一个XML PRSSING库,目的是编写ZC425268EESTRIP3333131310 ant3310 AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AM这些标签。

So, if the XML looks like this:因此,如果 XML 看起来像这样:

<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:我的 function 会收到这样的内容:

<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".并且 function 也会收到我们想要内容的标签的名称,所以如果标签是我的 function 将返回“狗”。

I am somewhat new in C++ and have no experience with C at all.我对 C++ 有点陌生,完全没有 C 的经验。 I found three different code samples here in Stack Overflow, which basically inherit from Expat's outline.c .我在 Stack Overflow 中找到了三个不同的代码示例,它们基本上继承自 Expat 的outline.c The samples are from this , this and this post.样本来自thisthisthis 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:

<?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:当我使用相同的 XML 运行这篇文章中的代码示例时,我得到的是:

 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.问题是我认为我会使用 Expat 的支持 unicode 的 dll,因为那是我会为任何可能发生的事情做好准备。 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.因此 expat 读取了每个元素或标签内容的第一个字符中的第二个字节,并认为它的空虚意味着这就是整个事情的结束并继续前进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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