Skip to main content
Known Participant
October 29, 2012
Question

xmlParse on poorly formatted xml

  • October 29, 2012
  • 3 replies
  • 1006 views

i'm trying to parse xml from a web service. the xml returned does not include the normal "<?xml...>" nor the ending tag. The remainder of the xml is well formed. What is the proper way to handle this?

    This topic has been closed for replies.

    3 replies

    BKBK
    Community Expert
    Community Expert
    October 29, 2012

    ggantzer2 wrote:

    i'm trying to parse xml from a web service. the xml returned does not include the normal "<?xml...>" nor the ending tag. The remainder of the xml is well formed. What is the proper way to handle this?

    Does the web service promise you an XML? If yes, examine whether it is your fault that the end tag is missing. If it is not your fault, report the problem to the service's publisher. 

    ggantzer2Author
    Known Participant
    October 29, 2012

    it does, and displays in a browser properly

    12Robots
    Participating Frequently
    October 29, 2012

    Do you mean the end tag for the <?xml...> beginning?  If so, then know that the is no ending tag for <?xml...>.

    If you are getting malformed errors it is because something else in the XML is malformed.

    Jason

    Inspiring
    October 29, 2012

    The initial <?xml?> tag is optional, so there's no need to worry about that bit.  However if the rest of the XML is malformed, what you should be doing is returning to however the XML is being generated and making it wellformed.  You should always try to resolve an issue so that it's correct before resorting to bandaiding something that is not correct.

    Still: if that's impossible, and if the only thing wrong is a single missing closing tag... just append the closing tag to the XML string.  But seriously: try to get it fixed at the time the XML is generated, not when you come to be processing it.

    --

    Adam

    ggantzer2Author
    Known Participant
    October 29, 2012

    when i do a cfdump, i'm not even seeing xml. but if i pull it up in a browser it looks nice.

    cfdump returns something like this:

    [{"Name":"Aspen 5 night stay.","DestinationId":3,"Destination":"Aspen ","Description":"First Tracks Promo: 5th Night/4th Day Free","MaximumSavings":415.0,"MinimumPrice":1394.0,"NumberOfNights":5,"Occupancy":2,"Featured":true,"FeaturedPosition":0,"ResortPosition":1,"FeaturedFrequency":50,"RequiresGroup":false,"LodgeSpecial":{"Name":"Aspen Square Studio","LodgeId":5,"Location":"Aspen, CO, US","OurRating":3.5,"Amenities":"Less than 250 yards to lift, On shuttle route, Walk to shuttle, Swimming pool - outdoor, Hot tub - outdoor, Concierge desk, Fitness faciliti

    A browser shows as:

    <ArrayOfSpecial xmlns:i="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://schemas.datacontract.org/2004/07/Ski.Domain.Specials">

    <Special>

    <Id xmlns="http://schemas.datacontract.org/2004/07/Ski">300027</Id>

    <CarRentalSpecial i:nil="true"/>

    <Description>First Tracks Promo: 5th Night/4th Day Free</Description>

    <Destination>Aspen</Destination>

    <DestinationId>3</DestinationId>

    <EquipmentRentalSpecial i:nil="true"/>

    <ExpirationDate>2012-11-01T00:00:00</ExpirationDate>

    <Featured>true</Featured>

    <FeaturedFrequency>50</FeaturedFrequency>

    <FeaturedPosition>0</FeaturedPosition>

    not exactly sure how to proceed.