Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6553753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:37:09+00:00 2026-05-25T12:37:09+00:00

given this xml file, i would like to extract the data out from it.

  • 0

given this xml file, i would like to extract the data out from it. However, i have trouble extracting the data from <LandmarkPointListXml> onwards.

The XML file:

  <?xml version="1.0" encoding="utf-8"?>
  <Map xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <MapName>er</MapName>
  <MapURL>er.gif</MapURL>
  <Name>er</Name>
  <URL>er.gif</URL>
  <LandmarkPointListXml>
    <anyType xsi:type="LandmarkPointProperty">
      <LandmarkPointX>400</LandmarkPointX>
      <LandmarkPointY>292</LandmarkPointY>
      <LandmarkDesc>my room door</LandmarkDesc>
    </anyType>
    <anyType xsi:type="LandmarkPointProperty">
      <LandmarkPointX>399</LandmarkPointX>
      <LandmarkPointY>219</LandmarkPointY>
      <LandmarkDesc>bro room door</LandmarkDesc>
    </anyType>
  </LandmarkPointListXml>
  <RegionPointListXml />
</Map>

Python program:

    def GetMapData(self):
        result = ""
        haha = self.XMLdoc.firstChild #root node
        for child in haha.childNodes:
            if (cmp(child.nodeName,'LandmarkPointListXml')==0):
                result = result + '|' + self.loopLandmark(child.childNodes) + '|'
            else:
                result = result + child.firstChild.nodeValue + ','
        return result

    def loopLandmark(self, landmarks):
        result=""
        haha=landmarks.getElementsByTagName('anyType')
        for child in haha.childNodes:
            if (cmp(haha.firstChild.nodeName,'LandmarkPointX') == 0):
                result=result+child.firstChild.nodeValue+','
                ChildNode = ChildNode.nextSibling
                result=result+child.firstChild.nodeValue+','
                ChildNode = ChildNode.nextSibling
                result=result+child.firstChild.nodeValue
        return result

I was able to retrieve the result, “er,er.gif,er,er.gif,” till the program reaches <LandmarkPointListXml>.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:37:10+00:00Added an answer on May 25, 2026 at 12:37 pm

    This code is quite fragile. It makes strong assumptions on the XML input, and would fail if the XML was modified in a valid way (e.g. if is not immediately after ).

    I suggest using a standard library when parsing XML, such as Element Tree ( http://docs.python.org/library/xml.etree.elementtree.html ) or lxml ( http://lxml.de ), which can also validate your XML input.

    The code I’m writing below uses Element Tree and works on your XML input (I have removed the ‘self’ arguments to the parent class). It also tolerates (ignores) empty values in XML elements.

    import xml.etree.ElementTree as ET
    
    def GetMapData( xmlfile ):
        result = ""
        try:
            tree = ET.parse( xmlfile )
        except IOError, e:
            print "Failure Parsing %s: %s" % (xmlfile, e)
        root = tree.getroot() # root node
        for child in root:
            if ( child.tag == 'LandmarkPointListXml' ):
                result += '|' + loopLandmark(child) + '|'
            elif child.text is not None:
                result += child.text + ','
        return result
    
    def loopLandmark( landmarks ):
        result=""
        for landmark in landmarks:
            if ( landmark.tag == 'anyType' ): # check also xsi:type="LandmarkPointProperty"?
                for child in landmark:
                    if ( child.text and child.tag in [ 'LandmarkPointX', 'LandmarkPointY' ] ):
                        result += child.text + ','
        return result
    
    GetMapData( 'xml.in' )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have this given XML file: <root> <node>x</node> <node>y</node> <node>a</node> </root> And I
I have an xml file that looks like this: ... <e1> <e2> <e3>content1.1</e3> <e3>content1.2</e3>
Given this example XML file: <doc> <tag> Hello ! </tag> <tag> My name is
Given an XML document like this: <!DOCTYPE doc SYSTEM 'http://www.blabla.com/mydoc.dtd'> <author>john</author> <doc> <title>&title;</title> </doc>
Given an XML structure like this: <garage> <car>Firebird</car> <car>Altima</car> <car>Prius</car> </garage> I want to
given an xml string like this: <some><nested><xml>value</xml></nested></some> what's the best option (using ruby) to
Given an xml structure like this <gesmes:Envelope> <gesmes:subject>Reference rates</gesmes:subject> <gesmes:Sender> <gesmes:name>European Central Bank</gesmes:name> </gesmes:Sender>
Given this XML: <mets:mets> <mets:fileSec> <mets:fileGrp ID=fileGrp001 USE=image/dynamic> <mets:file ID=filebib4112678_18760203_1_24_0001_m.jp2 MIMETYPE=image/jp2 SIZE=5308416 CREATED=2009-11-10T00:00:00 USE=image/dynamic
I have a bunch of hierarchical data stored in an XML file. I am
This seems like it should be simple but I can't work it out from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.