doing it using Enliveの一つの方法である:以下は、私はそれを開始したサンプルコードは、テキストベースの入力を読み取る
(ns tst.clj.core
(:use clj.core
tupelo.test)
(:require
[clojure.java.io :as io]
[net.cgrand.enlive-html :as en-html]
[tupelo.core :as t]))
(t/refer-tupelo)
; Discard any xml nodes of Type="A" or Type="B" (plus blank string nodes)
(dotest
(let [xml-str "<ROOT>
<Items>
<Item><Type>A</Type><Note>AA1</Note></Item>
<Item><Type>B</Type><Note>BB1</Note></Item>
<Item><Type>C</Type><Note>CC1</Note></Item>
<Item><Type>A</Type><Note>AA2</Note></Item>
</Items>
</ROOT>"
enlive-tree (->> xml-str
java.io.StringReader.
en-html/html-resource
first)]
(spyx-pretty enlive-tree)))
は結果で:
enlive-tree =>
{:tag :ROOT,
:attrs nil,
:content
("\n "
{:tag :Items,
:attrs nil,
:content
("\n "
{:tag :Item,
:attrs nil,
:content
({:tag :Type, :attrs nil, :content ("A")}
{:tag :Note, :attrs nil, :content ("AA1")})}
"\n "
{:tag :Item,
:attrs nil,
:content
({:tag :Type, :attrs nil, :content ("B")}
{:tag :Note, :attrs nil, :content ("BB1")})}
"\n "
{:tag :Item,
:attrs nil,
:content
({:tag :Type, :attrs nil, :content ("C")}
{:tag :Note, :attrs nil, :content ("CC1")})}
"\n "
{:tag :Item,
:attrs nil,
:content
({:tag :Type, :attrs nil, :content ("A")}
{:tag :Note, :attrs nil, :content ("AA2")})}
"\n ")}
"\n ")}
あなたがソケットから何か(テキスト文字列)を読み取ることができますに興味がある可能性があり
はい、私はソケットからテキストを読むことができますが、これは私が入手したものです: –
ソケット設定に何か間違っているはずです。 XMLは文字列内の単なる文字です(この例では 'xml-str'のように)。 "hello"、 " "、 "こんにちは、 "などの文字列を送信できることを確認してください。文字列を文字列に読み込むと、その文字列を解析できます。それは2つの別々の問題です。 –