久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在沒有 java 雙引號的情況下發送 Jaxb XmlAttr

How to send Jaxb XmlAttribute data without java double quotes(如何在沒有 java 雙引號的情況下發送 Jaxb XmlAttribute 數據)
本文介紹了如何在沒有 java 雙引號的情況下發送 Jaxb XmlAttribute 數據的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

所以我在嘗試使用 jaxb 從 java 類構建 xml 時遇到以下問題.我的第一個標簽需要是這樣的:

So I have the following issue when trying to build an xml from java class using jaxb. My first tag needs to be like this :

<Entity Type=‘test-instance’>
Some xml
</Entity>

我需要第一個標簽寫一些東西,但結束的標簽只需要實體.

I need the first tag to have something written in it but the closing one needs to have only Entity.

我創建了一個 claas 并添加了帶有 name=Entity 的 @XMLRootElement 標記,并且使用它我有正確的最后一個標記.如果我在第一個標簽和結束標簽中使用整個表達式,這對我沒有幫助.

I created a claas and added @XMLRootElement tag with name=Entity and using this I have the correct last tag. If I use the whole expression I have in both first and closing tag which does not help me.

我用@XMLAttribute 添加了一個String 變量,所以我可以在Entity 之后添加其他東西.問題是如果我用值初始化變量,我會得到字符串雙引號.例如

I added a String variable with @XMLAttribute so I can add something else after Entity. The problem is if I initialize the variable with value, I will get the String double quotes. For example

@XMLAttribute(name="Type")
String x = "test-instance";

當我構建它時,它將顯示:

When I build this it will read :

<Entity Type="test-instance">

,用雙引號,我只需要單引號.

, with double quotes and I need only single quotes.

如果在 xml 屬性中使用我需要的完整描述,例如:

If use the whole description I need in the xml attribute, for example :

@XMLAttribute(name="Type=‘test-instance’")
String x;

這可以正常工作,但如果變量沒有初始化,那么它不會添加任何東西,如果寫類似 String x=";然后我會得到:

This will work fine but if the variable is not initialized then it won’t add anything and if write something like String x=""; Then I will get :

<Entity Type=‘test-instance’="">

所以我無法擺脫來自我的字符串的引號.

So I cannot get rid of the quotes which are coming from my String.

我正在考慮對第一個實體標簽進行硬編碼,并讓我關閉它的最后一個標簽有所不同,但找不到任何東西.

I was thinking something to either hardcode the first Entity tag and to have the last one where I close it different but couldn’t find anything.

或者即使字符串沒有初始化,也可以設置 XMLAttribute 的另一個選項.我在 XMLElement 上看到了一些類似必需"的東西,但它不適用于 XMLAttribute,我不確定它是否能滿足我的需要它到.

Or the other option to set the XMLAttribute even if the String is not initialized.I saw something on the XMLElement that had something like "required" but it’s not available for XMLAttribute and I’m not really sure it does what I need it to.

任何幫助將不勝感激.

謝謝

推薦答案

在XML應用中的原則應該是:

In XML applications the principle should be:

(a) 接收應用程序不應該關心如何編寫 XML 的無關緊要的詞匯細節.(實現這一點的最佳方法是使用可觀的 XML 解析器來讀取 XML.)

(a) Receiving applications shouldn't care about the insignificant lexical detail of how the XML is written. (The best way of achieving this is to use a respectable XML parser to read the XML.)

(b) 編寫應用程序應該可以自由使用他們認為方便的任何詞匯約定.(這意味著您可以使用任何可敬的序列化庫來編寫 XML.)

(b) Writing applications should be free to use whatever lexical conventions they find convenient. (Which means you can use any respectable serialization library to write the XML.)

屬性的單引號或雙引號的選擇是這些無關緊要的詞匯細節之一.

The choice of single or double quotes for attributes is one of these insignificant lexical details.

我們在 StackOverflow 上看到很多問題是由于人們不遵守這些規則造成的.

We see a LOT of problems on StackOverflow caused by people not following these rules.

您還沒有解釋為什么需要生成單引號.也許 XML 正在被不遵循規則 (a) 的應用程序使用.在這種情況下,您應該修復它!如果你不能修復它,那么你的成本就會大大增加,事實上,使用 XML 毫無意義.

You haven't explained WHY you need to generate single quotes. Perhaps the XML is being consumed by an application that doesn't follow rule (a). In that case you should fix it! If you can't fix it, then you are vastly increasing your costs, in fact, there's very little point in using XML at all.

有時,當我們問這個問題時,我們會得到因為客戶堅持要那樣做"的答案.作為專業人士,我們的工作是教育我們的客戶:他們是在買單,將錢花在糟糕的工程上是不負責任的,即使他們說他們想要的也是如此.

Sometimes when we ask this question we get the answer "because by client insists on it being that way". It's our job as professionals to educate our clients: they're paying the bills and it's irresponsible to spend their money on bad engineering even if that's what they said they wanted.

這篇關于如何在沒有 java 雙引號的情況下發送 Jaxb XmlAttribute 數據的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Upload progress listener not fired (Google drive API)(上傳進度偵聽器未觸發(Google 驅動器 API))
Save file in specific folder with Google Drive SDK(使用 Google Drive SDK 將文件保存在特定文件夾中)
Google Drive Android API - Invalid DriveId and Null ResourceId(Google Drive Android API - 無效的 DriveId 和 Null ResourceId)
Google drive api services account view uploaded files to google drive using java(谷歌驅動api服務賬戶查看上傳文件到谷歌驅動使用java)
Google Drive service account returns 403 usageLimits(Google Drive 服務帳號返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例中缺少)
主站蜘蛛池模板: 国产综合久久久久久鬼色 | 精品一区二区久久久久久久网站 | 男女羞羞视频网站 | 国产日韩精品久久 | 91佛爷在线观看 | 九九视频网 | 亚洲一区二区三区 | 国产精品高潮呻吟久久av野狼 | 国产一区二区三区四区三区四 | 亚洲一区二区三区四区五区中文 | 亚洲国产精品人人爽夜夜爽 | 精品久久久久久久久久久 | 国产精品揄拍一区二区 | 久久免费小视频 | 91精品国产欧美一区二区 | 爱爱视频日本 | 久久精品视频91 | 日韩午夜网站 | 欧美韩一区二区 | 亚洲免费人成在线视频观看 | 亚洲福利在线观看 | 久久久av| 综合精品| 91在线观看网址 | 羞羞视频免费在线观看 | 成人免费淫片aa视频免费 | 国产精品免费看 | 国产在线精品一区二区三区 | 日韩免费高清视频 | 久久r精品 | 亚洲欧美中文日韩在线v日本 | 精品日韩在线 | 国产免费一区二区 | 成人免费淫片aa视频免费 | 国产亚洲精品精品国产亚洲综合 | 亚洲国产一区二区三区四区 | 国产清纯白嫩初高生在线播放视频 | 中文字幕一区二区视频 | 久久久久久99 | 天天插天天操 | 日本久久精品视频 |