问题描述
我需要您的帮助,我想使用GDataXMLDocument
解析XML文件,并且想获取特定标签的所有属性,但是当我使用或仅向我提供XPath的值以获取columnHeading值
I need your help, i want to parse an XML file using GDataXMLDocument
and i want to fetch particular tag's all attributes but when i am using or just provide me the XPath's value to get columnHeading value
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:[NSData dataWithContentsOfFile:path] encoding:NSUTF8StringEncoding error:NULL];
NSArray *tempArray = [doc nodesForXPath:@"//root/xsd:schema" namespaces:nil error:nil];
它返回以下错误.
XPath错误:未定义的名称空间前缀xmlXPathEval:评估失败
XPath error : Undefined namespace prefixxmlXPathEval: evaluation failed
这是我的XML内容.
<?xml version="1.0" encoding="utf-8"?>
<SH xmlns="urn:schemas-microsoft-com:xml-analysis:rowset">
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:saw-sql="urn:saw-sql" targetNamespace="urn:schemas-microsoft-com:xml-analysis:rowset">
<xsd:complexType name="R">
<xsd:sequence>
<xsd:element name="S0" saw-sql:columnHeading="SID" saw-sql:columnID="0"/>
<xsd:element name="S1" saw-sql:columnHeading="SNAME" saw-sql:columnID="1"/>
<xsd:element name="S2" saw-sql:columnHeading="CLASS" saw-sql:columnID="2"/>
<xsd:element name="S3" saw-sql:columnHeading="ADD" saw-sql:columnID="3"/>
<xsd:element name="S4" saw-sql:columnHeading="CITY" saw-sql:columnID="4"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
最近3天以来一直停留在这里.需要您的帮助.
Stuck here from last 3 days. need your help.
谢谢.
推荐答案
最后,我得到了与我的问题相关的解决方案...这是答案.
Finally i got the solution related to my question... and here is the answer for that.
GDataXMLDocument * doc = [[GDataXMLDocument alloc] initWithData:[NSData dataWithContentsOfFile:path]编码:NSUTF8StringEncoding错误:NULL];
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:[NSData dataWithContentsOfFile:path] encoding:NSUTF8StringEncoding error:NULL];
NSDictionary *myNS = [NSDictionary dictionaryWithObjectsAndKeys:
@"urn:schemas-microsoft-com:xml-analysis:rowset", @"xmlns",
@"http://www.w3.org/2001/XMLSchema", @"xsd",
@"urn:saw-sql",@"saw-sql", nil];
NSArray *tempArray = [doc nodesForXPath:@"//xmlns:RS/xsd:schema/xsd:complexType/xsd:sequence/xsd:element" namespaces:myNS error:nil];
NSMutableArray *keyArray = [[NSMutableArray alloc]initWithCapacity:0];
for(GDataXMLElement *columns in tempArray)
{
GDataXMLNode *xmlElement = [columns attributeForName:@"saw-sql:columnHeading"];
// GDataXMLNode* xmlElement = [[[element2 elementsForName:@"xsd:element"]objectAtIndex:0]attributeForName:@"saw-sql:columnHeading"];
[keyArray addObject:xmlElement.stringValue];
// NSLog(@"%@",xmlElement.stringValue);
}
这篇关于GDataXMLDocument nodesForXPath返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!