SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: XML parsing

  1. #1
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML parsing

    I am trying to delete "node" along with its children from an xml file.

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no" ?> 
    <gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxx="http://www.garmin.com/xmlschemas/WaypointExtension/v1" xmlns:gpxtrx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" creator="Oregon 550t" version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/WaypointExtension/v1 http://www8.garmin.com/xmlschemas/Wa...xtensionv1.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd">
    <metadata>
     <link href="http://www.abc.com">
      <text>abcl</text> 
      </link>
      <time>xyz</time> 
      </metadata>
      <trk>
      <name>sfa</name> 
    <node>
     <a>
      <gb>Black</gb> 
      </a>
    ........
     </node>
    The node is not deleted because of these long attribute values
    Code:
    <gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxx="http://www.garmin.com/xmlschemas/WaypointExtension/v1" xmlns:gpxtrx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" creator="Oregon 550t" version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/WaypointExtension/v1 http://www8.garmin.com/xmlschemas/WaypointExtensionv1.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd">
    How can I skip these while parsing?

  2. #2
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    These "long attribute values" as you call them are actually namespaces and have absolutely nothing to do with any problems you may have with deleting a node.

    Just tell us what node you want to delete and maybe someone can help you here (maybe even me but I'm not here all the time)
    My project: Open source Q&A
    (similar to StackOverflow)
    powered by php+MongoDB
    Source on github, collaborators welcome!

  3. #3
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to delete
    <node>
    <a>
    <gb>Black</gb>
    </a>
    </node>
    but I found that if there are namespaces, the deletion doesn't occur and if I remove namespaces, it does. I don't know why? But I will need namespaces along with deletion of node

  4. #4
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    What PHP code are you using at the moment to (fail to) delete the element? With SimpleXML, you can generally unset() the chosen element. With DOM, you can call removeChild() on the parent element.
    Salathe
    Software Developer and PHP Manual Author.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •