XML ফরম্যাটার
পাঠযোগ্য indentation সহ XML format করুন এবং element, attribute, text, comment ও escaped value বজায় রাখুন।
XML structure পড়া সহজ করুন
Compact XML পাঠাতে সুবিধাজনক হলেও পরীক্ষা করা কঠিন। সবকিছু এক line-এ থাকলে element, attribute, closing tag বা escaped character খুঁজে পাওয়া কঠিন হয়। এই formatter readable layout দেখায়, যাতে build, request বা configuration-এ ব্যবহারের আগে structure দেখা যায়।
Formatting presentation বদলায়, XML data-এর intended meaning নয়। এটি element name, attribute value, text node, comment ও entity reference রেখে consistent indentation এবং line break যোগ করে। Readable result পর্যালোচনার জন্য, schema validation-এর ফল নয়।
Tool শেখার সময় ছোট representative sample ব্যবহার করুন। Source document, formatted copy এবং পরের validation result আলাদা রাখুন, যাতে XML syntax, schema, encoding ও application rule আলাদা বোঝা যায়।
Document-এ secret বা personal data থাকলে paste করার আগে redacted copy তৈরি করুন। Formatting data anonymous করে না এবং অন্য service-এ পাঠানো অনুমোদিত প্রমাণ করে না।
Formatting এবং validation এক নয়
XML একটি nested markup format, যেখানে element, attribute, text, comment, declaration এবং character reference থাকে। Element-এর matching opening ও closing tag দরকার, attribute opening tag-এর অংশ এবং ampersand-এর মতো reserved character data হলে escape করতে হয়।
Formatter node ও whitespace সাজানোর মতো structure পড়ে। এটি XSD, DTD, namespace policy, application contract বা business rule মেনে চলছে কি না প্রমাণ করে না। এই checks যার দায়িত্ব সেই workflow-এ রাখুন।
কিছু XML context-এ whitespace data হতে পারে, বিশেষ করে mixed content এবং text node-এ। Whitespace-sensitive consumer-এ document বদলানোর আগে output তার requirements-এর সঙ্গে তুলনা করুন এবং original source রাখুন।
XML format করার পদ্ধতি
- Source field-এ সম্পূর্ণ XML document বা documented fragment paste করুন। Test copy থেকে unrelated prose ও programming-language wrapper বাদ দিন।
- Formatter চালিয়ে nesting, attribute, comment এবং text value পরীক্ষা করুন। Formatting failure থেকে নির্দিষ্ট parser message অনুমান করবেন না।
- Formatted document ও original তুলনা করুন। Element name, attribute value, entity reference, namespace declaration এবং text data অপরিবর্তিত আছে কি না দেখুন।
- Formatting-এর পর project-এর XML parser, schema validator বা application test চালান। Formatting একাই validity বা compatibility প্রমাণ করে না।
- Production data হলে sample থেকে secret ও personal information মুছুন। Controlled diff ও rollback-এর জন্য original file রাখুন।
Formatting method
- XML structure পড়া
Tool markup-কে nested XML content হিসেবে পড়ে এবং element, attribute, text, comment ও declaration-এর boundary চিহ্নিত করে।
- Indentation দেওয়া
Parent ও child সম্পর্ক দেখাতে formatter line break এবং indentation যোগ করে। এই whitespace presentation, নতুন schema rule নয়।
- Technical value রাখা
Attribute text, entity reference, namespace prefix ও comment source sample-এর সঙ্গে একই থাকতে হবে। Exact byte গুরুত্বপূর্ণ হলে diff দেখুন।
Public page XML formatting input document করে। Exact parser recovery, whitespace policy ও error wording live engine-এ পরীক্ষা না করে fixed behavior হিসেবে লিখবেন না।
Formatted result পড়া
Successful result দেওয়া XML-এর readable arrangement। Tree, value, attribute, comment ও declaration source-এর সঙ্গে মিলিয়ে দেখুন।
Failure মানে documented path input handle করতে পারেনি। Matching runtime evidence ছাড়া exact parser rule বা error location ধরে নেবেন না।
Document পরে XSD বা application check-এ fail করলে সেই আলাদা contract পরীক্ষা করুন। Formatting required element, namespace বা type যোগ করে না।
সাধারণ ভুল
Indentation-কে schema validation ভাবলে missing required element বা invalid attribute চোখ এড়াতে পারে।
Escaped entity-কে visible character দিয়ে বদলালে XML data বদলাতে পারে বা document invalid হতে পারে।
শুধু দেখতে ভালো লাগার জন্য attribute বা child sort করলে consumer-এর প্রত্যাশিত order বা mixed content বদলে যেতে পারে।
Required namespace declaration ছাড়া fragment copy করলে test production document-এর মতো থাকে না।
সীমাবদ্ধতা
Documented capability XML formatting। এটি XSD বা DTD validation, transformation, canonicalization, security scan বা application compatibility প্রমাণ করে না।
Whitespace-sensitive mixed content, namespace, বড় document এবং parser-specific recovery target consumer-এর সঙ্গে test করুন।
Policy অনুমতি না দিলে confidential production document paste করবেন না। Formatted copy-তে একই sensitive value থাকতে পারে।
Examples
Simple element format করা
Compact element কি readable করা যায়?
Compact XML পাঠান।
Child element-গুলো note-এর নিচে আলাদা indented line-এ দেখা যায়।
Attribute দেখা
Attribute-সহ element কীভাবে review করব?
Element পাঠিয়ে opening tag দেখুন।
id attribute user-এর সঙ্গে থাকে এবং name child indented হয়।
Escaped text রাখা
Text-এর entity কি একই থাকে?
Document format করে text node তুলনা করুন।
Entity reference text representation-এর অংশ হিসেবে থাকে।
Repeated child format করা
Repeated element কি আলাদা করে দেখানো যায়?
দুটি item child-সহ parent পাঠান।
প্রতিটি repeated child নিজের line-এ থাকে, তাই order দেখা সহজ।
Comment রাখা
XML comment-এর কী হয়?
Configuration sample format করুন।
Comment parent ও mode element-এর মধ্যে document-এ থাকে।
Declaration রাখা
XML declaration কীভাবে handle হয়?
Declaration ও root element একসঙ্গে পাঠান।
Declaration শুরুতে থাকে এবং root content নিচে indented হয়।
Frequently asked questions
Formatting কি XML schema validate করে?
না। এটি XML structure সাজায়। Schema check-এর জন্য project-এর XSD, DTD বা application validator ব্যবহার করুন।
Formatting কি element value বদলায়?
এটি value ও structure রেখে presentation whitespace যোগ করার কথা। Exact text গুরুত্বপূর্ণ হলে original-এর সঙ্গে তুলনা করুন।
Comment কি থাকে?
Examples comment-কে formatted view-তে থাকা content হিসেবে দেখায়। Pipeline-এ ব্যবহার করার আগে নিজের input-এ behavior নিশ্চিত করুন।
XML fragment কি format করা যায়?
Complete document বা documented fragment shape ব্যবহার করুন। Fragment missing namespace বা root-এর উপর নির্ভর করতে পারে।
Formatting কি XML ছোট করে?
না। Readability-এর জন্য সাধারণত whitespace যোগ হয়। Compact output-এর জন্য আলাদা minifier বা transport process ব্যবহার করুন।
Escaped ampersand কীভাবে রাখব?
& এর মতো reference XML data হিসেবে রাখুন। Context valid XML না থাকলে raw ampersand দিয়ে replace করবেন না।
Formatting কি malformed XML repair করে?
Automatic repair ধরে নেবেন না। Source ইচ্ছাকৃতভাবে ঠিক করে application-এর parser ও schema check চালান।
Format করার পরে কী করব?
Diff review করুন, parser বা schema check চালান এবং whitespace বা namespace গুরুত্বপূর্ণ হলে real consumer-এর সঙ্গে formatted copy test করুন।
