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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:40:02+00:00 2026-06-14T17:40:02+00:00

I am trying to write an xml parser using BeautifulSoup4 in Python. For some

  • 0

I am trying to write an xml parser using BeautifulSoup4 in Python. For some reason, the document is not being parsed correctly. My xml document is shown below:

<module id="BrainParser_1" name="Brain Parser" package="CCB" version="1" location="pipeline://cranium.loni.ucla.edu//usr/local/loniWorkflows/BrainParser/brainparser.sh" sourceCode="" icon="/9j/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAx&#xA;NDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy&#xA;MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAAUCABIAFYEASIAAhEBAxEBBCIA/8QAHwAAAQUB&#xA;A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Zqjr2rjSrXfFbNNKRgYX5V+ppLb&#xA;V7dwCJFLMcdeallKzRyb04btXY9jrautD6DorO0/XtJ1WWSOw1K1uZInKOsUoYgjrx+NaNaPhC6m&#xA;u9CiuLlRukYtx6dq5T4xrbP4RuHcHzlCCPn/AKaJn9M12dmY7OwiijUKir0HavDvil40ttbuY9N0&#xA;ydJ7WMZkmXOC2TlRkcjgHIyDnrXz1C8q115nmy2CvJv2hkVvhzExkKlb6PC5+9w1eqXNzDZ2stzc&#xA;OI4YkLu56KoGSa+Vfi38Uo/HUtvYaZFLFpVsxfMoAaWTpnHYAdPqa85imlglWWGR45F6OjEEfiK6&#xA;+z+J/iO2jjilnjuIl4YOgDMPTI6flXG0V6SbWxmeZRSyQSrLFI0ciHKuhwQfUGu3sPjD4608Rquu&#xA;yzLH/DcIr5+pIyfzrhaK7rUvijq93amGzQWbN1kV9xH04GP1rkbvVtSv023moXdwvpNMzj9TVOin&#xA;KTluC0PRda+NvjTWtNFkb2OzBPzy2amOR/bdnj8MVwl9qd/qciyX99c3bqMBriVpCB6ZJqrRRRRR&#xA;UgFFFFFKrMjq6MVZTkEHBBoooAKKKK1tE8RXmiah9qTE+SS6SsxBJIJPX73HU5r1Ox8f6Zqdzawo&#xA;0m52zIhQgoP5H8KKKpTlyuPc0jVlFWRp+H9dvPDeu2mr2DKLi2feoblW9QfYivqHwT8afD/i27i0&#xA;6ZJNO1GReEmI8tz6K3r7ECiio/HvxEhg06TTNMaX7VOm1pB8vlL3OeufTH1+vjNFFY06UaatEhu5&#xA;xvxt+KUfk3PhHR2Vy4AvLlW+7zny1x34GT74r59oooooorQQUUUUUUUUAFFFFFFFFABRRRX/2Q==" posX="80" posY="70" rotation="1">
    <authors>
        <author fullName="Mubeena Mirza" email="" website="" />
    </authors>
    <executableAuthors>
        <author fullName="Zhuowen Tu" email="" website="" />
        <author fullName="Bruce Liu" email="" website="" />
    </executableAuthors>
    <metadata>
        <data key="__creationDateKey" value="Tue Sep 11 10:28:28 PDT 2007" />
    </metadata>
    <input id="BrainParser_1.Structure" name="Structure" description="0: segmentation sub-cortical structures&#xA;1: sulci detection" required="false" enabled="true" order="0" prefix="-p" prefixSpaced="true" prefixAllArgs="false">
        <format type="Enumerated" cardinality="1">
            <enumeration>0</enumeration>
            <enumeration>1</enumeration>
            <enumeration>2</enumeration>
        </format>
        <values>
            <value>2</value>
        </values>
    </input>
    <input id="BrainParser_1.Testing" name="Testing" description="0: perform segmentation/detection&#xA;1: perform training&#xA;" required="false" enabled="true" order="1" prefix="-r" prefixSpaced="true" prefixAllArgs="false">
        <format type="Enumerated" cardinality="1">
            <enumeration>0</enumeration>
            <enumeration>1</enumeration>
        </format>
        <values>
            <value>0</value>
        </values>
    </input>
    <input id="BrainParser_1.SourceFile" name="Source File" description="In testing, it points to the source file in training, it points directory in which the training volumes are saved.&#xA;" required="true" enabled="true" order="2">
        <format type="File" cardinality="1">
            <fileTypes>
                <filetype name="Analyze Image" extension="img" description="Analyze Image">
                    <need>hdr</need>
                </filetype>
                <filetype name="Analyze Image" extension="img" description="Analyze Image file">
                    <need>hdr</need>
                </filetype>
            </fileTypes>
        </format>
    </input>
    <output id="BrainParser_1.TargetFile" name="Target File" description="In testing, it points to the target file in training, it points directory in which the trained classifiers are saved.&#xA;" required="true" enabled="true" order="3">
       <format type="File" cardinality="1">
           <fileTypes>
               <filetype name="Analyze Image" extension="img" description="Analyze Image">
                    <need>hdr</need>
               </filetype>
            </fileTypes>
        </format>
    </output>
    <input id="BrainParser_1.ModelsDirectory" name="Models Directory" description="Directory of trained models." required="false" enabled="true" order="4" prefix="-m" prefixSpaced="true" prefixAllArgs="false">
        <format type="Directory" cardinality="1" />
        <values>
            <value>pipeline://cranium.loni.ucla.edu//usr/local/loniWorkflows/BrainParser/56_Structure</value>
        </values>
    </input>
    <input id="BrainParser_1.NumberofStructures" name="Number of Structures" description="Only effective in training." required="false" enabled="false" order="5" prefix="-n" prefixSpaced="true" prefixAllArgs="false">
        <format type="Number" cardinality="1" />
        <values>
            <value>1</value>
        </values>
    </input>
    <input id="BrainParser_1.NumberofIterations" name="Number of Iterations" required="false" enabled="false" order="6" prefix="-t" prefixSpaced="true" prefixAllArgs="false">
        <format type="Number" cardinality="1" />
    </input>
    <input id="BrainParser_1.SmoothnessFactor" name="Smoothness Factor" description="Defalut=0.5, typical 0.0~2.0." required="true" enabled="true" order="7" prefix="-s" prefixSpaced="true" prefixAllArgs="false">
        <format type="Number" cardinality="1" />
        <values>
            <value>2.0</value>
        </values>
    </input>
</module>

The Python code I’ve written is shown below:

if __name__ == '__main__':
    soup = BeautifulSoup (
        open('test.xml'),
        'lxml'
    )

    for e in soup.find_all('module',attrs={'name':'Brain Parser'}):
        for i in e.find_all('input'):
            print i.prettify()

And this is the result:

<input description="0: segmentation sub-cortical structures 1: sulci detection" enabled="true" id="BrainParser_1.Structure" name="Structure" order="0" prefix="-p" prefixallargs="false" prefixspaced="true" required="false"/>

<input description="0: perform segmentation/detection 1: perform training" enabled="true" id="BrainParser_1.Testing" name="Testing" order="1" prefix="-r" prefixallargs="false" prefixspaced="true" required="false"/>

<input description="In testing, it points to the source file in training, it points directory in which the training volumes are saved. " enabled="true" id="BrainParser_1.SourceFile" name="Source File" order="2" required="true"/>

<input description="Directory of trained models." enabled="true" id="BrainParser_1.ModelsDirectory" name="Models Directory" order="4" prefix="-m" prefixallargs="false" prefixspaced="true" required="false"/>

<input description="Only effective in training." enabled="false" id="BrainParser_1.NumberofStructures" name="Number of Structures" order="5" prefix="-n" prefixallargs="false" prefixspaced="true" required="false"/>

<input enabled="false" id="BrainParser_1.NumberofIterations" name="Number of Iterations" order="6" prefix="-t" prefixallargs="false" prefixspaced="true" required="false"/>

<input description="Defalut=0.5, typical 0.0~2.0." enabled="true" id="BrainParser_1.SmoothnessFactor" name="Smoothness Factor" order="7" prefix="-s" prefixallargs="false" prefixspaced="true" required="true"/>

As you can see, it thinks that input has no child elements, but this is not the case. I did some poking around, and it seems that elements like value and format are parsed as children of the module element. Can anybody help with this?

  • 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-06-14T17:40:03+00:00Added an answer on June 14, 2026 at 5:40 pm

    You are calling BeautifulSoup with "lxml", which tells it to use the lxml parser and parse the input as HTML. (In HTML, input tags are self-closing and don’t have children, so your string is not valid HTML. BeautifulSoup does its magic HTML fixing and decides that you meant the input tag to close itself immediately, which is why you are not seeing any children.)

    You want to call it with "xml", which tells it that the input is an XML document.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a generic XML to Core Data parser using libxml2. Since
I'm trying to parse a simple xml document using a DOM parser in JS,
I've been trying to write a PHP script to parse an XML document using
I'm trying to write an XML document using an XmlWriter and an XmlDocument .
I am trying to write a xml parser in C using the libxml2 on
I am trying to write some XML schema code to specify that a particular
I'm trying to write an xml file with utf-8 encoded data using ElementTree like
I am trying to write XML data using Stax where the content itself is
I'm trying to write a unit test that checks some xml parsing code. The
I'm trying to develop simple Python (3.2) code to read XML files, do some

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.