Could anybody please tell me how to extract the first 30 characters of the contents from XML file?
A:
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.
Alex
2009-12-02 07:52:49
reading the first 200 bytes doesn't work. It might very well contain only tags, leaving you with less than 30 characters ;^)
Toad
2009-12-02 07:54:52
yeah yeah yeah. Ideally, get the first X chars, run the regex, if not enough, get more bytes.
Alex
2009-12-02 08:00:28
+7
A:
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.
Charlie Salts
2009-12-02 07:53:02
I'm tired and I don't give a sh*t. Ask a silly question - get a silly answer :)
Charlie Salts
2009-12-02 07:56:39
Reviewing my comment, `hadn't had` - is that even correct oO? Too early to speak english *yawn*...
ApoY2k
2009-12-02 07:59:51
A:
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
Dave Kirby
2009-12-02 08:00:54
+1
A:
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
Robert Rossney
2009-12-03 18:35:57