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?

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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!!!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.