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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:35:03+00:00 2026-06-03T08:35:03+00:00

I am new to using XML in Delphi, and have used the questions already

  • 0

I am new to using XML in Delphi, and have used the questions already posted to find out most of what I need to know (thank you!). However … I am struggling to obtain a data value from the top of the XML file issued by one of our suppliers.

The top of the XML file is shown below:

<?xml version="1.0" encoding="utf-8"?>
<form billId="1004" penId="ABCDE" appName="Report Sheet" penSerialNo="AJX-AAT-AGK-B4" >
<question id="1" reference="site_name" value="Acme Inc" /></question>
<question id="2" reference="site_address" value="London" /></question>
<question id="3" reference="TQM_job_no" value="AB1234567" /></question>
<question id="4" reference="TQM_site_no" value="XX999" /></question>

How can I obtain the penId and penSerialNo values?

For reference, I am using the code below, obtained from another post on the site, to traverse the XML and obtain the values from the question nodes:

for i:= 0 to XMLDocument1.DocumentElement.ChildNodes.Count - 1 do
   begin
       Node:= XMLDocument1.DocumentElement.ChildNodes[I];
 if Node.NodeName = 'question' then
  begin
   if Node.HasAttribute('value') then
    VALUEvar:= Node.Attributes[value'];
    // do something with VALUEvar which is a string
      end;
end;
end;

I would really appreciate any help that could be provided … thanks in advance!

  • 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-03T08:35:04+00:00Added an answer on June 3, 2026 at 8:35 am

    Since form is your root node, you can use something like this:

    uses
      XMLDoc, XMLIntf;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      XMLDocument: IXMLDocument;
    begin
      XMLDocument := LoadXMLDocument('c:\YourFile.xml');
      if XMLDocument.DocumentElement.HasAttribute('penId') then
        ShowMessage(VarToStr(XMLDocument.DocumentElement.Attributes['penId']));
      if XMLDocument.DocumentElement.HasAttribute('penSerialNo') then
        ShowMessage(VarToStr(XMLDocument.DocumentElement.Attributes['penSerialNo']));
    end;
    

    Anyway, your document is invalid. You cannot use tags enclosed like:

    <tag attr="value"/></tag>
    

    Either use:

    <tag attr="value"/>
    

    or

    <tag attr="value"></tag>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to PHP. I need to GET a xml stored locally using
Im new using Python, now I have a problem using ElementTree and read out
I am new to iPhone and using XML in my application where i need
I'm using the new System.Xml.Linq to create HTML documents (Yes, I know about HtmlDocument,
Completely new to using simple XML library in PHP, and have been using the
I've referenced System.Xml: using System.Xml; Then in this line: XmlDocument xdoc = new XmlDocument();
I am using a new service to pull xml data from a server. The
I'm new to XML validation using .xsd files. Maybe I'm not even asking the
using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();
I'm creating an XML document. I got it to indent using TransformerFactory.setAttribute(indent-number, new Integer(2));

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.