Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Sax Xml解析器属性_Android_Xml Parsing_Saxparser - Fatal编程技术网

Android Sax Xml解析器属性

Android Sax Xml解析器属性,android,xml-parsing,saxparser,Android,Xml Parsing,Saxparser,我正在使用SAX解析xml文件,但无法获得“y”的值 这是xml <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type= "text/html" ?> <Chart1 count="3"> <Sales_x0020_Amount Label="Sales Amount"> <Chart1_CategoryGroup_Col

我正在使用SAX解析xml文件,但无法获得“y”的值

这是xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type= "text/html" ?>
<Chart1 count="3">
            <Sales_x0020_Amount Label="Sales Amount">
               <Chart1_CategoryGroup_Collection>
                  <Chart1_CategoryGroup Label="URC 1">
                     <Value Y="30434929.1" />
                     <name>keeevin</name>
                  </Chart1_CategoryGroup>
                  <Chart1_CategoryGroup Label="URC 2">
                     <Value Y="39757503.83" />
                     <name>kevin2</name>
                  </Chart1_CategoryGroup>
                  <Chart1_CategoryGroup Label="URC 3">
                     <Value Y="19611069.73" />
                     <name>kevin</name>
                  </Chart1_CategoryGroup>
               </Chart1_CategoryGroup_Collection>
            </Sales_x0020_Amount>
</Chart1>
谢谢

编辑: 我在这里设置了一个断点,它不会通过这里

static class MyHandler extends DefaultHandler {
    public void startElement(String namespaceURI, String localName,
                             String qName, Attributes atts)  {
        // Get the number of attribute
        int length = atts.getLength();

    // Process each attribute
    for (int i=0; i<length; i++) {
        // Get names and values for each attribute
        String name = atts.getQName(i);
        String value = atts.getValue(i);
        if(qName == "Value"){
             y = atts.getValue(i);
        }
        String nsUri = atts.getURI(i);
        String lName = atts.getLocalName(i);
    }
}

在处理程序(扩展的DefaultHandler)中的startElement方法中写入


您的startelement将是图表,在该计数中将是属性,该属性将出现在if部分中,而不是在else if部分中,销售金额将出现,该属性将是标签。请参阅。

您可以解释参数吗?qName-标记名(在这一行中qName=值)属性-atributes数组,元素从索引0开始(在这一行中,此调用属性。getValue(0)返回(Y属性的值)39757503.83),但其他参数呢?我应该传递什么值?请参阅java文档中的内容,谢谢。我也发现了这个。如果我要加载一个托管xml,而不是本地xml,您如何实现这一点?
static class MyHandler extends DefaultHandler {
    public void startElement(String namespaceURI, String localName,
                             String qName, Attributes atts)  {
        // Get the number of attribute
        int length = atts.getLength();

    // Process each attribute
    for (int i=0; i<length; i++) {
        // Get names and values for each attribute
        String name = atts.getQName(i);
        String value = atts.getValue(i);
        if(qName == "Value"){
             y = atts.getValue(i);
        }
        String nsUri = atts.getURI(i);
        String lName = atts.getLocalName(i);
    }
}
    public void startElement(String uri, String localName, String qName,
                Attributes attributes) throws SAXException {

            elementOn = true;

    if (localName.equals("Chart"))
            {
                data = new XMLGettersSetters();
            }
            if (qName.equals("Value")) {
                String attributeValue = attributes.getValue(0);
                data.setValue(attributeValue);
            }
}
public void startElement(String uri, String localName, String qName,
        Attributes attributes) throws SAXException {
    if (qName.equals("Value")) {
                 map.put("Y", "Y Coord:" + attributes.getValue(0));
            }
    }