@@ -8,19 +8,22 @@ internal static class Tag
88 public static Doc PrintOpeningTag ( XElement element , XmlPrintingContext context )
99 {
1010 return Doc . Concat (
11- PrintOpeningTagStart ( element ) ,
11+ PrintOpeningTagStart ( element , context ) ,
1212 Attributes . Print ( element , context ) ,
1313 element . IsEmpty ? Doc . Null : PrintOpeningTagEnd ( element )
1414 ) ;
1515 }
1616
17- private static Doc PrintOpeningTagStart ( XElement element )
17+ private static Doc PrintOpeningTagStart ( XElement element , XmlPrintingContext context )
1818 {
1919 return
2020 element . PreviousNode is not null
2121 && NeedsToBorrowNextOpeningTagStartMarker ( element . PreviousNode )
2222 ? Doc . Null
23- : Doc . Concat ( PrintOpeningTagPrefix ( element ) , PrintOpeningTagStartMarker ( element ) ) ;
23+ : Doc . Concat (
24+ PrintOpeningTagPrefix ( element ) ,
25+ PrintOpeningTagStartMarker ( element , context )
26+ ) ;
2427 }
2528
2629 private static Doc PrintOpeningTagEnd ( XElement node )
@@ -60,37 +63,40 @@ private static bool NeedsToBorrowPrevClosingTagEndMarker(XNode node)
6063 ;
6164 }
6265
63- public static Doc PrintClosingTag ( XElement node )
66+ public static Doc PrintClosingTag ( XElement node , XmlPrintingContext context )
6467 {
6568 return Doc . Concat (
66- node . IsEmpty ? Doc . Null : PrintClosingTagStart ( node ) ,
67- PrintClosingTagEnd ( node )
69+ node . IsEmpty ? Doc . Null : PrintClosingTagStart ( node , context ) ,
70+ PrintClosingTagEnd ( node , context )
6871 ) ;
6972 }
7073
71- public static Doc PrintClosingTagStart ( XElement element )
74+ public static Doc PrintClosingTagStart ( XElement element , XmlPrintingContext context )
7275 {
7376 var lastChild = element . Nodes ( ) . LastOrDefault ( ) ;
7477
7578 return lastChild is not null && NeedsToBorrowParentClosingTagStartMarker ( lastChild )
7679 ? Doc . Null
77- : Doc . Concat ( PrintClosingTagPrefix ( element ) , PrintClosingTagStartMarker ( element ) ) ;
80+ : Doc . Concat (
81+ PrintClosingTagPrefix ( element ) ,
82+ PrintClosingTagStartMarker ( element , context )
83+ ) ;
7884 }
7985
80- public static Doc PrintClosingTagStartMarker ( XElement element )
86+ public static Doc PrintClosingTagStartMarker ( XElement element , XmlPrintingContext context )
8187 {
82- return $ "</{ GetPrefixedElementName ( element ) } ";
88+ return $ "</{ GetPrefixedElementName ( element , context ) } ";
8389 }
8490
85- public static Doc PrintClosingTagEnd ( XElement node )
91+ public static Doc PrintClosingTagEnd ( XElement node , XmlPrintingContext context )
8692 {
8793 return (
8894 node . NextNode is not null
8995 ? NeedsToBorrowPrevClosingTagEndMarker ( node . NextNode )
9096 : NeedsToBorrowLastChildClosingTagEndMarker ( node . Parent ! )
9197 )
9298 ? Doc . Null
93- : Doc . Concat ( PrintClosingTagEndMarker ( node ) , PrintClosingTagSuffix ( node ) ) ;
99+ : Doc . Concat ( PrintClosingTagEndMarker ( node ) , PrintClosingTagSuffix ( node , context ) ) ;
94100 }
95101
96102 public static bool NeedsToBorrowLastChildClosingTagEndMarker ( XElement node )
@@ -116,29 +122,32 @@ public static Doc PrintClosingTagEndMarker(XElement node)
116122 return node . IsEmpty ? "/>" : ">" ;
117123 }
118124
119- public static Doc PrintClosingTagSuffix ( XNode node )
125+ public static Doc PrintClosingTagSuffix ( XNode node , XmlPrintingContext context )
120126 {
121127 return NeedsToBorrowParentClosingTagStartMarker ( node )
122- ? PrintClosingTagStartMarker ( node . Parent ! )
128+ ? PrintClosingTagStartMarker ( node . Parent ! , context )
123129 : NeedsToBorrowNextOpeningTagStartMarker ( node )
124- ? PrintOpeningTagStartMarker ( node . NextNode ! )
130+ ? PrintOpeningTagStartMarker ( node . NextNode ! , context )
125131 : Doc . Null ;
126132 }
127133
128- private static Doc PrintOpeningTagStartMarker ( XNode node )
134+ private static Doc PrintOpeningTagStartMarker ( XNode node , XmlPrintingContext context )
129135 {
130136 if ( node is not XElement element )
131137 {
132138 return "<" + node ;
133139 }
134140
135- return $ "<{ GetPrefixedElementName ( element ) } ";
141+ return $ "<{ GetPrefixedElementName ( element , context ) } ";
136142 }
137143
138- private static string GetPrefixedElementName ( XElement element )
144+ private static string GetPrefixedElementName ( XElement element , XmlPrintingContext context )
139145 {
140146 var prefix = element . GetPrefixOfNamespace ( element . Name . Namespace ) ;
141- if ( string . IsNullOrEmpty ( prefix ) )
147+ if (
148+ string . IsNullOrEmpty ( prefix )
149+ || ! context . Mapping [ element ] . Name . StartsWith ( prefix , StringComparison . Ordinal )
150+ )
142151 {
143152 return element . Name . LocalName ;
144153 }
0 commit comments