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

  • Home
  • SEARCH
  • 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 340715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:38:31+00:00 2026-05-12T10:38:31+00:00

When I receive XML data (via a Twitter API call, in this instance), I

  • 0

When I receive XML data (via a Twitter API call, in this instance), I imagine it’s best practice to somehow validate it before I begin working with it? My app has had a lot of untractable issues lately, and I want to rule out bad XML data.

Does XML ever go “bad” somehow? Would an overloaded server like Twitter’s ever spit out just half of what should come my way?

My real question is twofold: should I validate XML data before I work with it, and how would I go about doing that? (I already know the supposed structure of the XML data)

Thanks!

One last clarification before I select an answer (and thanks for your efforts): If I only need 5 predictable fields out of the static-length XML file, does something like this leave loopholes that creating an XSD overcomes?

if(!isset($xml->id, $xml->text, $xml->created_at, $xml->sender, $xml->recipient)) throw...
  • 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-12T10:38:31+00:00Added an answer on May 12, 2026 at 10:38 am

    The most obvious method of validating your XML would be:

    1. Attempt to load the XML into your favourite
      DOM container or parse it using some other mechanism (I’m not completely familair with XML processing in PHP). This would allow you to check if the XML is ‘well formed’. If the XML is not well formed
      (i.e. you only got half the XML
      response back) then you’d catch this
      problem at this point and deal with
      it.

    2. Once you’ve successfully
      loaded/parsed the XML the next thing
      is to validate it against an XML
      schema. Unfortunately Twitter don’t
      publish XML schemas for their XML so
      you’d need to roll these yourself.

    You can create your own XML schema’s by hand. Here’s a link that will help you get started:

    XML Schema Tutorial (W3 Schools)

    You can also get tools such as Altova XMLSpy that can ‘infer’ a schema from your XML. i.e. it makes a best guess as to how to define the schema, you may have to tweak it after generation. There are other free tools out there but I’ve only ever used XMLSpy. As Alan says, if Twitter ever change the format for their XML you would need to update your schemas to take account for these changes.

    Creating XML Schemas can be daunting at first but once you get the hang of it you’ll find it quite easy. I found this book to be excellent when I first started out:

    XML Schema – The W3C’s Object-Oriented Descriptions for XML (O’Reilly Press)

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

Sidebar

Ask A Question

Stats

  • Questions 166k
  • Answers 166k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You are not going to be able to do this… May 12, 2026 at 1:19 pm
  • Editorial Team
    Editorial Team added an answer You could use reflection to dynamically create a XmlAttributeOverrides object… May 12, 2026 at 1:19 pm
  • Editorial Team
    Editorial Team added an answer If you want to select all direct children of a… May 12, 2026 at 1:19 pm

Related Questions

I'm encountering a problem while trying to serialize a multi-dimensioned array of integers via
I've got a struts2 action that responds to an AJAX request by taking some
I would really appreciate any suggestions, no matter how simple or complex, to help
I am having problems manually looping through xml data that is received via an

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.