How to convert a HTML file to XML file?

How can I convert an XML file to Text file using XPath?

  • I have a file in XML and now I want to convert this file from xml to text. for example if I have in file <Location>LE5 5AB</Location>. Now I want to extract Location and LE5 5AB separately and output I want this as a text using XPath.

  • Answer:

    The answer depends on why you want to create an XML to text converter. If your goal is to produce a text document with fitted columns, numbered or bulleted lists, tables, and other formatting, your converter will need to include a composition capability. If your intent is simply to separate out the element and content semantics for text-only content of the element (as if for passing these values into a form or database), this simple use of XPath queries (the match and select attributes) in XSLT logic will do: <xsl:template match="Location"> Element name: <xsl:value-of select="name()"/><br/> Content value: <xsl:value-of select="."/> or <xsl:value-of select="text()"/><br/> </xsl:template> For your given sample, this produces: Element name: Location Content value: LE5 5AB or LE5 5AB I hope this very basic answer helps. If not, please describe your requirement or question in more detail, and include some use cases.

Don Day at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.