Convert html to xml php

I would update the old tags with something like this,

$field = preg_replace['/\]+][?/', '', $field];

You can see it here

Using a negative lookbehind we can match all unclosed img tags, capture the "guts" in each one, and then replace it with a closed tag.

  • \]+] capture anything that is not a >
  • [? negative lookbehind, match the ending > if not preceded by a /, ie. matches > not />

So given a tag like this

it will capture \1, [{}to show spacing is captured]

 { alt="" height="239" src="//example.com/image.png" width="272"}

Then we simply replace the with a /> and put the "guts" back in with \1

And our tag is now closed


This could be expanded with another capture group and a list of tags like this:

$field = preg_replace['/\]*][?/', '', $field];

And now it will match
and replace it with
as well as the img tag. All the while ignoring closed tags like this:


See this one here

So, it's not impossible.

I feel obligated to mention, that you should always export a backup of the table before doing any changes of this sort of scope. That way you can be sure if something is wrong you have a safety net.

Convert HTML to XML online helps to convert HTML Table to xml which saves a lot a time. Copy, Paste and Convert to XML. It traverse the DOM and look for tables from the HTML data.

What can you do with HTML to XML?

  • This tool helps you to get plain xml from html table very quickly without writing single line of code.
  • From HTML to XML free allows loading the Website URL which has tables converting to XML. Click on the URL button, Enter URL and Submit.
  • Parsing HTML into XML supports loading the HTML File to transform to XML. Click on the Upload button and select File.
  • HTML to Plain XML Converter Online works well on Windows, MAC, Linux, Google Chrome, Firefox, Edge, and Safari.

Example of HTML

HTML with Table Try it.


			firstName
			lastName
		
Tom Cruise
Maria Sharapova
James Bond

Converted HTML 2 XML


	
		Tom
		Cruise
	
	
		Maria
		Sharapova
	
	
		James
		Bond
	

For Advanced Users

HTML with Table External URL

Load HTML External URL in Browser URL like this //codebeautify.org/html-to-xml-converter?url=external-url

//codebeautify.org/html-to-xml-converter?url=//gist.githubusercontent.com/cbmgit/644916fb1e435ddc367233c6d785652f/raw/html-table.html

HTML Table To XML Converter lets you convert HTML Table to XML online. Select an HTML file or Load HTML from a url or Enter HTML Table data and convert it to XML. Beautify HTML, XML and download converted XML data to your device.

  • Load Url
  • Browse
  • Convert
  • Beautify html
  • Beautify XML
  • Editor Options
  • Download
  • Clear

Enter Url

Message

Editor Options

Themes

Font Size

Enter html here:

Results:

Simple HTML to XML conversion. Demonstrates how the HTML is auto-corrected to create well-formed XML. In this example, the closing

is missing. Also, text is encapsulated in nodes with the intent to make it easy for programs to identify and extract the text parts.

Chủ Đề