Jump to content

How to fix errors in XML file using php program?


hmdnawaz

Recommended Posts

<?xml version="1.0" encoding="ISO-8859-1"?>

 

<Note>

<from>

Ahmad

</from>

<to>

Yasir

</to>

<body>

hello yasir.

 

</Note>

 

 

Above is my xml file which misses the ending tag of <body>.

i want a php program that will detect this error and also fix the error and place the ending tag.

can someone help me?

You need to specify our document type definition at the top of your xml file.

 

<!DOCTYPE note

[

<!ELEMENT note (to,from,heading,body)>

<!ELEMENT to (#PCDATA)>

<!ELEMENT from (#PCDATA)>

<!ELEMENT body (#PCDATA)>

]>

 

This way the XML parser will know what to expect. It will validate your XML against that info.

 

the links you provided only checks that the document is valid or not.

and i want to check the document and if there is no end tag of a tag then add the ending tag of that tag.

 

Will get all nodes of the document and store them in a variable and then perform checks on that variable.

 

Hope you get my problem!!!

Then the job gets a bit harder. I don't know any XML parser that would also validate the invalid parts of xml string. If you don't know what the XML string should contain. Then it is a very big job to write parser for that. But if you know what you need to validate then you could write your own validator which checks that all tags are closed in the right order.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.