开发者

Get Xml from raw resource in android

开发者 https://www.devze.com 2023-04-10 23:12 出处:网络
I have a problem that I am getting an xml file from raw resource for parsing but I can\'t get it due to an error please suggest me the right result to solve below mentioned error:

I have a problem that I am getting an xml file from raw resource for parsing but I can't get it due to an error please suggest me the right result to solve below mentioned error:

Error Stack:

 10-06 18:59:50.323: ERROR/AndroidRuntime(1100): FATAL EXCEPTION: main
10-06 18:59:50.323: ERROR/AndroidRuntime(1100): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.xml/com.example.xml.TestXmlActivity}: org.w3c.dom.DOMException: SãoPaulo
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at android.os.Looper.loop(Looper.java:123)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at android.app.ActivityThread.main(ActivityThread.java:4627)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at java.lang.reflect.Method.invokeNative(Native Method)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at java.lang.reflect.Method.invoke(Method.java:521)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at dalvik.system.NativeStart.main(Native Method)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100): Caused by: org.w3c.dom.DOMException: SãoPaulo
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at org.apache.harmony.xml.dom.ElementImpl.<init>(ElementImpl.java:69)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at org.apache.harmony.xml.dom.DocumentImpl.createElement(DocumentImpl.java:333)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:346)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:362)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:362)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:135)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:110)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at com.example.xml.TestXmlActivity.onCreate(TestXmlActivity.java:40)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
10-06 18:59:50.323: ERROR/AndroidRuntime(1100):     ... 11 more

XML:

<?xml version="1.0" encoding="UTF-8"?>
<metro>

    <america>
        <Atlanta>
            <MetroGeneralInfo>
                Strategically positioned in Atlanta's 500,000 ft,
                and 160,000 ft fully dedicated carrier hotel/interconnect facilities
                are Atlanta 1, Atlanta 2, and Atlanta 3 IBX Data Centers, catering
                to the Southeast's largest concentration of telecommunication
                companies who take advantage of the dynamic ecosystem of networks
                and business partners operating within the IBX. All of the Atlanta
                IBX centers offer a full range of premium colocation,
                interconnection and support services.
            </MetroGeneralInfo>

            <MetroFeaturedEcosystem>
                At Equinix, we recognize that organizations
                in different industries
                face unique challenges and have different
                needs and priorities. The
                combination of Equinix’s rich customer
                base, aggregation of networks
                and presence in strategic global
                markets like Atlanta creates
                thriving business ecosystems across key
                industry segments.

                Financial Services:

                60+ exchanges and trading
                platforms
                400+ buy- and sell-side firms
                150+ financial service
                providers
                The GUIDE tool to help financial firms quickly understand
                and visualize
                the interconnected global financial markets Ability to
                quickly
                deploy in the top 16 global financial centers
                Access to
                exchanges, trading platforms, market data providers and other
                enabling partners a cross connect away
                675+ network options to
                control bandwidth costs

                Cloud &amp; IT Services:

                250+ cloud and 450+
                IT service providers
                Base of enterprise customers and carrier MPLS
                backbones reachable via
                the Equinix Marketplace
                Access to 675+ public
                and private networks to optimize performance and hit
                latency targets
                Specialized exchanges for Internet, Ethernet, and mobility
                Available
                capacity in 38 major business and population centers across Europe,
                the Americas and Asia-Pacific

                Enterprise:

                Maximization of supplier
                choice while taking advantage of onsite solution
                management partners
                to minimize complexity
                Accelerated deployment of virtual and cloud
                solutions
                Optimized performance by placing cloud applications within
                your enterprise
                Empowering of users through broadband and mobility
                connections
            </MetroFeaturedEcosystem>

            <ToatalProvider>
                85
            </ToatalProvider>

            <CloudItCustomer>
                15
            </CloudItCustomer>

        </Atlanta>

        <Boston>
            <MetroGeneralInfo>
                The Equinix Boston IBX Data Center is located
                within a two-story
                building near Bell Atlantic, offering colocation
                services with
                multiple connectivity and interconnection options. This
                data center
                offers fiber diversity and multiple layers of security.
                Boston BO1
                IBX Data Center offers a full range of premium colocation,
                interconnection and support services.
            </MetroGeneralInfo>

            <MetroFeaturedEcosystem>
                Financial Services:

                60+ exchanges and trading
                platforms
                400+ buy- and sell-side firms
                150+ financial service
                providers
                The GUIDE tool to help financial firms quickly understand
                and visualize
                the interconnected global financial markets
                Ability to
                quickly deploy in the top 16 global financial centers
                Access to
                exchanges, trading platforms, market data providers and other
                enabling partners a cross connect away
                675+ network options to
                control bandwidth costs

                Cloud &amp; IT Services:

                250+ cloud and 450+
                IT service providers
                Base of enterprise customers and carrier MPLS
                backbones reachable via
                the Equinix Marketplace
                Access to 675+ public
                and private networks to optimize performance and hit
                latency targets
                Specialized exchanges for Internet, Ethernet, and mobility
                Available
                capacity in 38 major business and population centers across Europe,
                the Americas and Asia-Pacific

                Enterprise:

                Maximization of supplier
                choice while taking advantage of onsite solution
                management partners
                to minimize complexity
                Accelerated deployment of virtual and cloud
                solutions
                Optimized performance by placing cloud applications within
                your enterprise
                Empowering of users through broadband and mobility
                connections
            </MetroFeaturedEcosystem>


            <ToatalProvider>
                30
            </ToatalProvider>
            <CloudItCustomer>
            </CloudItCustomer>
        </Boston>
             <Paris>
            <MetroGeneralInfo>
                One of the leading business hubs in Europe, Paris
                is a focal point of
                Europe's banking, commerce, transport, and
                telecommunications
                infrastructure. Many major carriers are connected
                to the site,
                making it an ideal place to procure competitive
                bandwidth costs.
                These features, coupled with the prime location in
                the heart of this
                metropolitan center, make it an ideal disaster
                recovery and business
                continuity facility for large corporate
                operations, as well as ISP
                and system integrators where security and
                capacity are paramount to
                colocation customers. The Paris IBX data
                centers benefit from
                Equinix’s high standards of specification and
                are certified ISO
                9001: 2008. From Paris we offer a full range of
                colocation,
                interconnection, support, and monitoring services.
            </MetroGeneralInfo>
            <MetroFeaturedEcosystem>
                In Paris, we know that organizations in
                different industries face
                unique challenges and have different needs
                and priorities. The
                combination of our rich customer base,
                aggregation of networks and
                presence in strategic global markets like
                Paris creates thriving
                business ecosystems across key industry
                segments.

                Content &amp; Digital Media:

                Direct access to end-user
                networks including MSOs, ISPs and mobile data
                providers
                Specialized
                ecosystem of 450+ content providers for direct connection to
                partners including the top social media and ad networks
                Diverse
                choice among all top CDNs and leading Internet transit providers
                Proximity to end users in 11 countries across 4 continents
                over 6
                million square feet and continuously investing to ensure
                consistent
                availability for expansion

                Cloud &amp; IT Services:

                250+ cloud and
                450+ IT service providers
                Base of enterprise customers and carrier
                MPLS backbones reachable via
                the Equinix Marketplace
                Access to 625+
                public and private networks to optimize performance and hit
                latency
                targets
                Specialized exchanges for Internet, Ethernet, and mobility
                Available capacity in 38 major business and population centers
                across Europe,
                North America and Asia-Pacific

                Networks:

                Widest choice
                of network providers with 625+
                Ability to leverage the broadest
                network choice for optimum IT performance,
                resiliency and cost
                control
                Improved performance with providers that deliver low-latency
                reach to
                end-users
                Reduced time-to-market by leveraging direct
                connections between corporate
                WAN providers and enterprise, cloud and
                managed service providers
                Ability to choose one global infrastructure
                partner, while retaining
                flexibility to optimize regional and local
                network structure

            </MetroFeaturedEcosystem>
            <ToatalProvider>
            </ToatalProvider>
            <CloudItCustomer>
            </CloudItCustomer>
        </Paris>

        <Zürich>
            <MetroGeneralInfo>
                Zürich’s IBX data centers are located in the heart
                of the city, providing
                excellent carrier connectivity from the main
                telecommunication
                crossroad in Zurich. The central location of the
                IBX data centers
                makes Zurich an ideal place for network service
                providers who
                deliver into the banking district as well as companies
                who are based
                in the financial services and media capital of Europe.
                The Zürich
                IBX data centers provide purpose-built, highly specified
                colocation
                space with meeting and office space. All sites are
                connected via
                redundant networks for truly resilient dual-site
                solutions. Services
                include Equinix Exchange, which enables customers
                to peer through a
                central switching fabric managed by Equinix. The
                Zürich IBX data
                centers benefits from Equinix’s high standards of
                specification and
                are certified ISO 9001: 2008. The Zürich IBX data
                centers offer a
                full range of colocation, interconnection, support,
                and monitoring
                services.
            </MetroGeneralInfo>
            <MetroFeaturedEcosystem>
                In Zürich, we know that organizations in
                different industries face
                unique challenges and have different needs
                and priorities. The
                combination of our rich customer base,
                aggregation of networks and
                presence in strategic global markets like
                Zurich creates thriving
                business ecosystems across key industry
                segments.

                Financial Services:

                60+ exchanges and trading platforms
                400+
                buy- and sell-side firms
                150+ financial service providers
                The GUIDE
                tool to help financial firms quickly understand and visualize
                the
                interconnected global financial markets
                Local ecosystems and ability
                to quickly deploy in the top 16 global
                financial centers
                Access to
                exchanges, trading platforms, market data providers and other
                enabling partners a cross connect away
                625+ network options to开发者_Python百科
                control bandwidth costs

                Cloud &amp; IT Services:

                250+ cloud and 450+
                IT service providers
                Base of enterprise customers and carrier MPLS
                backbones reachable via
                the Equinix marketplace
                Access to 625+ public
                and private networks to optimize performance and hit
                latency targets
                Specialized exchanges for internet, Ethernet, and mobility
                Available
                capacity in 38 major business and population centers across Europe,
                North America and Asia-Pacific

                Networks:

                Widest choice of network
                providers with 625+
                Ability to leverage the broadest network choice
                for optimum IT performance,
                resiliency and cost control
                Improved
                performance with providers that deliver low-latency reach to
                end-users
                Reduced time-to-market by leveraging direct connections
                between corporate
                WAN providers and enterprise, cloud and managed
                service providers
                Ability to choose one global infrastructure
                partner, while retaining
                flexibility to optimize regional and local
                network structure


            </MetroFeaturedEcosystem>
            <ToatalProvider>
            </ToatalProvider>
            <CloudItCustomer>
            </CloudItCustomer>
        </Zürich>

        <Zwolle>
            <MetroGeneralInfo>
                The Zwolle IBX data center is an important location
                for our primary
                customer segment, SMEs, but it can also serve as a
                business
                continuity / fall-back location for our customers located in
                Amsterdam or Enschede. We offer from the Netherlands a portfolio of
                managed services specifically developed for the SME segment. Managed
                Services compliment a full range of colocation, interconnection,
                support and monitoring services available from this location. The
                IBX data center in Zwolle has been designed to the highest standards
                of security, cooling, and power density. Zwolle benefits from our
                high standards of specification and is certified ISO 9001: 2008,
                OHSAS 18001:2007, and ISO/IEC 27001:2005. All locations in the
                Netherlands are interconnected via a redundant backbone with 24/7
                monitoring.
            </MetroGeneralInfo>
            <MetroFeaturedEcosystem>
                At Equinix, we recognize that organizations
                in different industries
                face unique challenges and have different
                needs and priorities. The
                combination of Equinix’s rich customer
                base, aggregation of networks
                and presence in strategic global
                markets like Zwolle creates
                thriving business ecosystems across key
                industry segments.

                Cloud &amp; IT Services:

                250+ cloud and 450+ IT
                service providers
                Base of enterprise customers and carrier MPLS
                backbones reachable via
                the Equinix marketplace
                Access to 625+ public
                and private networks to optimize performance and hit
                latency targets
                Specialized exchanges for internet, Ethernet, and mobility
                Available
                capacity in 38 major business and population centers across Europe,
                North America and Asia-Pacific

                Enterprise:

                Maximization of supplier
                choice while taking advantage of on-site solution
                management partners
                to minimize complexity
                Accelerated deployment of virtual and cloud
                solutions
                Optimized performance by placing cloud applications within
                your enterprise
                Empowering of users through broadband and mobility
                connections

                Networks:

                Widest choice of network providers with 625+
                Ability to leverage the broadest network choice for optimum IT
                performance,
                resiliency and cost control
                Improved performance with
                providers that deliver low-latency reach to
                end-users R
                educed
                time-to-market by leveraging direct connections between corporate
                WAN providers and enterprise, cloud and managed service providers
                Ability to choose one global infrastructure partner, while retaining
                flexibility to optimize regional and local network structure


            </MetroFeaturedEcosystem>
            <ToatalProvider>
            </ToatalProvider>
            <CloudItCustomer>
            </CloudItCustomer>
        </Zwolle>

    </Europe>


    <AsiaSpecific>

        <HongKong>
            <MetroGeneralInfo>
                Hong Kong is a vital center for international
                finance and trade in
                Asia-Pacific. Multinational companies take
                advantage of the global
                reach and direct access to a vibrant
                ecosystem of enterprises,
                networks, IT and cloud service providers
                located within our Hong
                Kong IBX data centers. The robust standards
                of the IBX design and
                infrastructure provide a consistent base of
                operations for many
                mission-critical applications. Equinix Business
                Continuity solutions
                are also offered in Hong Kong to support our
                financial services
                customers’ recovery requirements in any unexpected
                contingency. Hong
                Kong is also the location of the regional
                headquarters for Equinix’s
                Asia-Pacific operations.
            </MetroGeneralInfo>
            <MetroFeaturedEcosystem>
                At Equinix, we recognize that organizations
                in different industries
                face unique challenges and have different
                needs and priorities. The
                combination of Equinix’s rich customer
                base, aggregation of networks
                and presence in strategic global
                markets like Hong Kong creates
                thriving business ecosystems across
                key industry segments.

                Financial Services:

                60+ exchanges and trading
                platforms
                400+ buy- and sell-side firms
                150+ financial service
                providers
                The GUIDE tool to help financial firms quickly understand
                and visualize
                the interconnected global financial markets
                Ability to
                quickly deploy in the top 16 global financial centers
                Access to
                exchanges, trading platforms, market data providers and other
                enabling partners a cross connect away
                675+ network options to
                control bandwidth costs

                Cloud &amp; IT Services:

                250+ cloud and 450+
                IT service providers
                Base of enterprise customers and carrier MPLS
                backbones reachable via
                the Equinix Marketplace
                Access to 675+ public
                and private networks to optimize performance and hit
                latency targets
                Specialized exchanges for Internet, Ethernet, and mobility
                Available
                capacity in 38 major business and population centers across Europe,
                the Americas and Asia-Pacific

                Enterprise:

                Maximization of supplier
                choice while taking advantage of onsite solution
                management partners
                to minimize complexity
                Accelerated deployment of virtual and cloud
                solutions
                Optimized performance by placing cloud applications within
                your enterprise
                Empowering of users through broadband and mobility
                connections

            </MetroFeaturedEcosystem>
            <ToatalProvider>
            </ToatalProvider>
            <CloudItCustomer>
            </CloudItCustomer>
        </HongKong>

    </AsiaSpecific>
</metro>

Code:

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;
        try {
            builder = factory.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Document dom = null;


My understanding of the logcat is that it actually succesfully open the XML file but throws a org.w3c.dom.DOMException around SãoPaulo.

Add a generic Exception catcher after your builder.parse() try block.

i.e.

    //your code
    try {
        dom = builder.parse(is);
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // add this
    catch (Exception e){
       e.printStackTrace();
    }


It's dead at this line:

dom = builder.parse(is);

Maybe, there's something wrong in XML format, such as wrong encoding and data, tag not close...

0

精彩评论

暂无评论...
验证码 换一张
取 消