Could anybody please tell me how to extract 开发者_如何学运维the first 30 characters of the contents from XML file?
Open the file in notepad, and select the first 30 characters. Hit Ctrl-C.
If you want to do this programmatically, you'll need to tell us what language you're using.
On linux/unix/cygwin:
head -c 30 myfile.xml
If you want the first 30 text characters outside of the tags then:
1) install xmltwig - this is a perl module, so you will need to install perl if you do not have it. Xmltwig includes the xml_grep utility.
2) run:
xml_grep --text_only myfile.xml | head -c 30
In C#, after reading the XML into an XmlDocument
:
string s = doc.DocumentElement.InnerText.Substring(0, 30);
This returns the first 30 characters of the text nodes in the document, e.g.:
<foo>This is <bar>some sort of <baz>crazy</baz> markup.</bar></foo>
will return:
This is some sort of crazy mar
Open the file Ask the file stream reader to read in first 30 bytes Close the file
If you want the non-tag 30 characters, read the first 200 bytes, then run a regular expression to remove the tags.
精彩评论