从VBA解析XML无法正常工作

时间:2015-06-10 06:30:10

标签: xml excel vba excel-vba

我正在尝试使用excel vba解析xml文件。这就是我的xml文件的样子:

var ikj = Model.EmployeeInformationList
               .Select(m => new HolidayAlwEmployeeInfo()
                            {
                                GEmployeeGenInfoID=m.GEmployeeGenInfoID,
                                strDesignationName=m.strDesignationName,
                                strEmpOldCardNo=m.strEmpOldCardNo,
                                StrEmpID=m.StrEmpID,
                                GFactoryID=m.GFactoryID,
                                StrEmpName=m.StrEmpName
                            })
               .Distinct()
               .ToList();

这是我解析它的代码:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Environment>
    <Variable>
        <Name></Name>
        <Caption>T1</Caption>
        <Type>TEXT</Type>
        <Value>V1</Value>
        <Description></Description>
    </Variable>
        <Variable>
        <Name></Name>
        <Caption>T2</Caption>
        <Type>TEXT</Type>
        <Value>V2</Value>
        <Description></Description>
    </Variable>
        <Variable>
        <Name></Name>
        <Caption>T3</Caption>
        <Type>TEXT</Type>
        <Value>V3</Value>
        <Description></Description>
    </Variable> <Variable>
        <Name></Name>
        <Caption>T4</Caption>
        <Type>TEXT</Type>
        <Value>V4</Value>
        <Description></Description>
    </Variable> <Variable>
        <Name></Name>
        <Caption>T5</Caption>
        <Type>TEXT</Type>
        <Value>V5</Value>
        <Description></Description>
    </Variable>
    </Variable> <Variable>
        <Name></Name>
        <Caption>T6</Caption>
        <Type>TEXT</Type>
        <Value>V6</Value>
        <Description></Description>
    </Variable>
</Environment>

但我无法成功运行。我使用的是Excel 2013,我引用了Microsoft XML 6.0。但执行没有任何反应。我试图用错误语句捕获错误,但它返回错误号0.任何人都可以告诉我这里做错了什么。

1 个答案:

答案 0 :(得分:0)

XML解析器只有在XML格式良好的情况下才能工作。如果不是,则_image = [[imagesModel alloc] initFromURLWithString:imageURL completion:^(id model, JSONModelError *err) { int x = 0; int w = 1; for (imageModel *img in _image.Images) { NSString *picString = [NSString stringWithFormat:picURL, img.filename]; NSLog(@"Images: %@", picString); UIImage *getImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:picString]]]; UIImageView *imageView2 = [[UIImageView alloc] initWithImage:getImage]; self.pictureScroll.contentSize = CGSizeMake(w * 123, 120); imageView2.frame = CGRectMake(x * 123, 1, 120, 120); x++; w++; [pictureScroll addSubview:imageView2]; UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected)]; singleTap.numberOfTapsRequired = 1; [imageView2 setUserInteractionEnabled:YES]; [imageView2 addGestureRecognizer:singleTap]; clicked = img.filename; // hide the loader view } [HUD hideUIBlockingIndicator]; }]; 方法失败。

要检查这一点,您可以使用oXMLDOMDocument.load,如下所示:

oXMLDOMDocument.parseError

请参阅:https://msdn.microsoft.com/en-us/library/ms762722%28v=vs.85%29.aspx