Try XML Tools. Plugins -> XML Tools -> Pretty Print (libXML) or (XML only - with line breaks Ctrl + Alt + Shift + B)
You may need to install XML Tools using your plugin manager in order to get this option in your menu.
In my experience, libXML gives nice output but only if the file is 100% correctly formed.
Answer from erjiang on Stack OverflowVideos
Try XML Tools. Plugins -> XML Tools -> Pretty Print (libXML) or (XML only - with line breaks Ctrl + Alt + Shift + B)
You may need to install XML Tools using your plugin manager in order to get this option in your menu.
In my experience, libXML gives nice output but only if the file is 100% correctly formed.
You need to install XML Tools from the Plugins menu item โ Plugins Admin... โ Plugins Admin dialog appears and then scroll to bottom of available plugins and check XML Tools, install it and then Ctrl + Alt + Shift + B OR the option for XML Tools above shows up.
Going from XML to text smells like a job for XSLT - it's a XML-based transformation language that can take an XML input and convert it to anything text-based on the output side.
You can read up on XSLT on lots of websites - one of the better tutorials in the W3Schools one.
Since you didn't post any sample XML, I have no clue what your XML looks like, and also no idea what your output should be. But assuming it would look something like:
<?xml version="1.0" encoding="utf-8"?>
<root>
<title>Some Title</title>
<description>Some description</description>
<keywords>
<keyword>Keyword1</keyword>
<keyword>Keyword2</keyword>
<keyword>Keyword3</keyword>
<keyword>Keyword4</keyword>
</keywords>
</root>
you could easily write a XSLT transformation to turn that into
YourTextFile.txt
Some Title
Some Description
Keyword1,Keyword2,Keyword3,Keyword4
or whatever other format you are looking for.
My suggestion would be to use Python. You can use the interpreter to run the pattern while you are setting it up, command line goes along way in setting this sort of thing up properly. Assuming the xml is valid this should allow you the most flexibility with the least hassle.
so assuming the following xml format:
<root>
<title>Document Title</title>
<content>Some document content.</content>
<keywords>test, document, keyword</keywords>
</root>
and assuming the output of each document should be:
Document Title
Some document content.
test, document, keyword
The python code might look something like:
import sys
import os
from xml.etree.ElementTree import ElementTree
def Readthexml(f):
"""Read the file from the argument list and dump the title contents and keywords"""
xcontent = ElementTree()
xcontent.parse(f)
doc = [xcontent.find("title").text, xcontent.find("content").text, xcontent.find("keywords").text]
out = open(f + ".txt", "w")
out.write("\n\n".join(doc))
return True
def main(argv=None):
if argv is None:
argv = sys.argv
args = argv[1:]
for arg in args:
if os.path.exists(arg):
Readthexml(arg)
if __name__ == "__main__":
main()
from which you could generate a batch file to update files regularly (assuming it is a windows environment though python works in whatever).
Assuming xmlDoc is an XmlDocument object whats wrong with xmlDoc.OuterXml?
return xmlDoc.OuterXml;
The OuterXml property returns a string version of the xml.
There aren't any quotes. It's just VS debugger. Try printing to the console or saving to a file and you'll see. As a side note: always dispose disposable objects:
using (var stringWriter = new StringWriter())
using (var xmlTextWriter = XmlWriter.Create(stringWriter))
{
xmlDoc.WriteTo(xmlTextWriter);
xmlTextWriter.Flush();
return stringWriter.GetStringBuilder().ToString();
}