ما هي الطريقة الصحيحة للتعامل مع ورقة XML: XMLNS: بلاه مع هامل؟

StackOverflow https://stackoverflow.com/questions/1567614

  •  21-09-2019
  •  | 
  •  

سؤال

أحاول توصيل مدونة ببعض مساحات أسماء XML وورائح أنماط XML.

الطريقة القبيحة التي أقوم بها في الوقت الحالي تبدو كذلك:

!!! XML
= partial('xmlstyle')
%channel
......blah.....
= partial('xmlend')

أين

_xmlstyle.xml.erb يشبه:

<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?>
<?xml-stylesheet type="text/css" media="screen" 
href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/" 
xmlns:dc="http://purl.org/dc/elements/1.1/" 
xmlns:atom="http://www.w3.org/2005/Atom" 
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" 
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

يشبه _xmlend.xml.erb:

</rss>

هل يجب أن ألتزم بـ ERB الآن؟ يجب أن تكون هناك وسيلة للقيام بذلك في هامل ، أليس كذلك؟

هل كانت مفيدة؟

المحلول

لا يحتوي Haml على بناء جملة لتوجيهات ورقة الأنماط XML ، ولكن لا يوجد سبب لعدم إدراجه مباشرة. أما بالنسبة لل xmlns:blah سمات ، يمكنك إما استخدام السلاسل كأسماء السمات ، مثل ذلك:

<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?>
<?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?>
%rss{"xmlns:content" => "http://purl.org/rss/1.0/modules/content/",
     "xmlns:wfw" => "http://wellformedweb.org/CommentAPI/",
     "xmlns:dc" => "http://purl.org/dc/elements/1.1/",
     "xmlns:atom" => "http://www.w3.org/2005/Atom",
     "xmlns:sy" => "http://purl.org/rss/1.0/modules/syndication/",
     "xmlns:slash" => "http://purl.org/rss/1.0/modules/slash/",
     "xmlns:feedburner" => "http://rssnamespace.org/feedburner/ext/1.0",
     :version => "2.0"}
  %channel
    blah

يمكنك أيضًا استخدام سمات على غرار HTML مع ():

<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?>
<?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?>
%rss(xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
     xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0"
     version="2.0")
  %channel
    blah
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top