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 3754732
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:35:25+00:00 2026-05-19T09:35:25+00:00

Hi Guys i have problem parsing an xml file and entering the data to

  • 0

Hi Guys i have problem parsing an xml file and entering the data to sqlite, the format is like i need to enter the chracters before the token like 111,AAA,BBB etc

<DOCUMENT>
<PAGE width="544.252" height="634.961" number="1" id="p1">
<MEDIABOX x1="0" y1="0" x2="544.252" y2="634.961"/>

<BLOCK id="p1_b1">

<TEXT width="37.7" height="74.124" id="p1_t1" x="51.1" y="20.8652">
<TOKEN sid="p1_s11" id="p1_w1" font-name="Verdanae" bold="yes" italic="no">111</TOKEN>
</TEXT>
</BLOCK>

<BLOCK id="p1_b3">

<TEXT width="151.267" height="10.725" id="p1_t6" x="24.099" y="572.096">
<TOKEN sid="p1_s35" id="p1_w22" font-name="Verdanae" bold="yes"     italic="yes">AAA</TOKEN>
<TOKEN sid="p1_s36" id="p1_w23" font-name="verdanae" bold="yes" italic="no">BBB</TOKEN>
<TOKEN sid="p1_s37" id="p1_w24" font-name="verdanae" bold="yes" italic="no">CCC</TOKEN>
</TEXT>
</BLOCK>

<BLOCK id="p1_b4">

<TEXT width="82.72" height="26" id="p1_t7" x="55.426" y="138.026">
<TOKEN sid="p1_s42" id="p1_w29" font-name="verdanae" bold="yes" italic="no">DDD</TOKEN>
<TOKEN sid="p1_s43" id="p1_w30" font-name="verdanae" bold="yes" italic="no">EEE</TOKEN>
</TEXT>

<TEXT width="101.74" height="26" id="p1_t8" x="55.406" y="162.026">
<TOKEN sid="p1_s45" id="p1_w31" font-name="verdanae" bold="yes" italic="no">FFF</TOKEN>
</TEXT>

<TEXT width="152.96" height="26" id="p1_t9" x="55.406" y="186.026">
<TOKEN sid="p1_s47" id="p1_w32" font-name="verdanae" bold="yes" italic="no">GGG</TOKEN>
<TOKEN sid="p1_s48" id="p1_w33" font-name="verdanae" bold="yes" italic="no">HHH</TOKEN>
</TEXT>
</BLOCK>
</PAGE>
</DOCUMENT>

in .net it is done with 3 foreach loops 1. for “DOCUMENT/PAGE/BLOCK” 2.”TEXT” 3. “TOKEN” and then it is entered into the DB i dont get how to do it in python and i am trying it with lxml module

  • 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-19T09:35:25+00:00Added an answer on May 19, 2026 at 9:35 am

    you mean this?:

    >>> xml = """<DOCUMENT>
    ... <PAGE width="544.252" height="634.961" number="1" id="p1">
    ... <MEDIABOX x1="0" y1="0" x2="544.252" y2="634.961"/>
    ... 
    ... <BLOCK id="p1_b1">
    ... 
    ... <TEXT width="37.7" height="74.124" id="p1_t1" x="51.1" y="20.8652">
    ... <TOKEN sid="p1_s11" id="p1_w1" font-name="Verdanae" bold="yes" italic="no">111</TOKEN>
    ... </TEXT>
    ... </BLOCK>
    ... 
    ... <BLOCK id="p1_b3">
    ... 
    ... <TEXT width="151.267" height="10.725" id="p1_t6" x="24.099" y="572.096">
    ... <TOKEN sid="p1_s35" id="p1_w22" font-name="Verdanae" bold="yes"     italic="yes">AAA</TOKEN>
    ... <TOKEN sid="p1_s36" id="p1_w23" font-name="verdanae" bold="yes" italic="no">BBB</TOKEN>
    ... <TOKEN sid="p1_s37" id="p1_w24" font-name="verdanae" bold="yes" italic="no">CCC</TOKEN>
    ... </TEXT>
    ... </BLOCK>
    ... 
    ... <BLOCK id="p1_b4">
    ... 
    ... <TEXT width="82.72" height="26" id="p1_t7" x="55.426" y="138.026">
    ... <TOKEN sid="p1_s42" id="p1_w29" font-name="verdanae" bold="yes" italic="no">DDD</TOKEN>
    ... <TOKEN sid="p1_s43" id="p1_w30" font-name="verdanae" bold="yes" italic="no">EEE</TOKEN>
    ... </TEXT>
    ... 
    ... <TEXT width="101.74" height="26" id="p1_t8" x="55.406" y="162.026">
    ... <TOKEN sid="p1_s45" id="p1_w31" font-name="verdanae" bold="yes" italic="no">FFF</TOKEN>
    ... </TEXT>
    ... 
    ... <TEXT width="152.96" height="26" id="p1_t9" x="55.406" y="186.026">
    ... <TOKEN sid="p1_s47" id="p1_w32" font-name="verdanae" bold="yes" italic="no">GGG</TOKEN>
    ... <TOKEN sid="p1_s48" id="p1_w33" font-name="verdanae" bold="yes" italic="no">HHH</TOKEN>
    ... </TEXT>
    ... </BLOCK>
    ... </PAGE>
    ... </DOCUMENT>"""
    >>> from lxml import etree
    >>> parsed = etree.fromstring(xml)
    >>> tokens = parsed.xpath('//TOKEN/text()')
    >>> tokens
    ['111', 'AAA', 'BBB', 'CCC', 'DDD', 'EEE', 'FFF', 'GGG', 'HHH']
    >>> 
    

    or this?:

    >>> parsed = etree.fromstring(xml)
    >>> for block in parsed.xpath('//PAGE/BLOCK/TEXT'):
    ...     print block.xpath('./TOKEN/text()')
    ... 
    ['111']
    ['AAA', 'BBB', 'CCC']
    ['DDD', 'EEE']
    ['FFF']
    ['GGG', 'HHH']
    >>> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello guys i have a little problem i get an error: File C:\Users\kokki\Desktop\gb1\main.py, line
Ok guys, I have a serious problem with this. I have a static class
Hey guys, I have a weird problem. I have an update system that refreshes
Problem solved: Thanks guys, see my answer below. I have a website running in
I hope some of you guys can help me with this problem.... I have
hi guys i have two pipe delimited files,first file contains 1000 records and second
Hey Guys I have four integer array lists which were created after parsing a
Hi I was wondering if you guys have a problem with Tank Auth. After
Hello guys I have a problem with my application involving Lucene java library and
Hi guys have a problem with renaming a set of files in separate folder

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.