Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Process And Fix Xml String

process xml string

  • Please log in to reply
4 replies to this topic

#1 shr

shr

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 14 April 2012 - 06:44 AM

I have an HTML file from which I extract useful info and save it as XML in a string. This XML data within the string contains a few urls enclosed in quotes. urls with special characters can make the whole XML file invalid. How to rectify this?

I've used htmlspecialchars already but it also converts the valid characters such as '<' in '<outline' into '&lt;' which I do not want it to do. I simply want the urls/titles/names etc to be checked whether they are valid; or if they are not, they must be made valid. I've considered passing each url through htmlspecialchars but it slows down process a lot.

A part of my xml string looks as follows:


<outline title="inspiration" text="inspiration">

<outline text="Paul Graham" title="Paul Graham" type="rss" xmlUrl="http://www.aaronsw.com/2002/feeds/pgessays.rss" htmlUrl="http://www.paulgraham.com/index.html"/>

<outline text="Flickr: Shreeda Kumar&#39;s Photostream" title="Flickr: Shreeda Kumar&#39;s Photostream" type="rss" xmlUrl="http://api.flickr.com/services/feeds/photos_public.gne?id=47780284@N06&amp;lang=en-us&amp;format=rss_200" htmlUrl="http://www.flickr.com/photos/shreeda-kumar/"/>

<outline text="Lea Verou | Life at the bleeding edge (of web standards)" title="Lea Verou | Life at the bleeding edge (of web standards)" type="rss" xmlUrl="http://lea.verou.me/feed/" htmlUrl="http://lea.verou.me/"/>

</outline>

  • 0

#2 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 14 April 2012 - 06:57 AM

How do you create your XML? Do you use a XML DOM object or do you do it "manually"? PHP has some nice features in both SimpleXML (http://se.php.net/ma...k.simplexml.php) and the DOM (http://se.php.net/ma...en/book.dom.php) extention, which I guess could simplify a lot for you?
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#3 shr

shr

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 14 April 2012 - 07:10 AM

How do you create your XML? Do you use a XML DOM object or do you do it "manually"? PHP has some nice features in both SimpleXML (http://se.php.net/ma...k.simplexml.php) and the DOM (http://se.php.net/ma...en/book.dom.php) extention, which I guess could simplify a lot for you?


I'm doing it "manually". I had come across those pages in the past but it didn't help then because my PHP knowledge is.... inferior. If you could kindly clarify my doubts, I'll go in that way.

I have two simple questions:
1) Would using simplexml/dom extension handle dangerous urls?
2) If yes, among simplexml and dom extension which do you recommend?

In case you have the time to share some tips or pointers on this, I would be grateful.
  • 0

#4 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 14 April 2012 - 07:16 AM

As I understand, they would only do proper XML files. I'm most used to SimpleXML and I like it very much.
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#5 shr

shr

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 14 April 2012 - 07:25 AM

As I understand, they would only do proper XML files. I'm most used to SimpleXML and I like it very much.


Okay. Thanks for your time, Orjan. I'll look into both of them and see if I can manage to solve the problem.
  • 0





Also tagged with one or more of these keywords: process, xml, string

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download